2013-10-22 57 views
-1

你好,我得到这个错误:不是一个声明,错误是在行130,returnphonetype;Java编译器错误:不是一个声明,这是什么意思?

我也不能像它以前那样编译它,没有语法错误。

我的代码:

public class Mobile 

{ 
    // type of phone 
private String phonetype; 
    // size of screen in inches 
private int screensize; 
    // memory card capacity 
private int memorycardcapacity; 
    // name of present service provider 
private String mobileServiceProvider; 
    // type of contract with service provider 
private int mobileTypeOfContract; 
    // camera resolution in megapixels 
private int cameraresolution; 
    // the percentage of charge left on the phone 
private int chargeUp; 
    // wether the phone has GPS or not 
private int switchedOnFor; 
    // to simulate using phone for a period of time 
private int charge; 
    // checks the phones remaining charge 
private String provider; 
    // simulates changing the provider 
private String GPS; 
    // instance variables - replace the example below with your own 


    // The constructor method 

public Mobile(String mobilephonetype, int mobilescreensize, 
int mobilememorycardcapacity, String mobileServiceProvider, int mobileTypeOfContract, int mobilecameraresolution, String mobileGPS, int chargeUp,int switchedOnFor, String changeProvider,int getBalance) { 
    // initialise the class attributes from the one given as parameters in your constructor. 
} 


/** 
* Other constructor 
*/ 
public Mobile (int cost) { 
    // initialise cost(?) attribute that actually doesn't seem to exist? 
} 

/** 
*returns a field price. 
    */ 
public int getPrice() 
    { 
return price; 
    } 

     //this.serviceprovider = newserviceprovider; 
     //this.typeofcontract = 12; 
     //this.checkcharge = checkcharge; 
     //this.changeProvider = giffgaff; 

    //Mobile samsungPhone = new Mobile(
// "Samsung" // String mobilephonetype 
//, 1024 // intmobilescreensize 
//, 2  // intmobilememorycardcapacity 
//, 8  // intmobilecameraresolution 
//, "GPS" //String mobileGPS 
//, "verizon" // String newserviceprovider 
//, "100" // intchargeUp 
//, "25" // intswitchedOnFor 
//, "25" // intcheckCharge 
//,  "giffgaff"// String changeProvider 
//); 


     //typeofcontract = 12; 
     //checkcharge = checkcharge; 


    //Mutator for newserviceprovider 
public void setmobileServiceProvider(String newmobileServiceProvider) 
    { 
mobileServiceProvider = newmobileServiceProvider; 
    } 
    //Mutator for contracttype 
public void setmobileTypeOfContract(int newmobileTypeOfContract) 
    { 
mobileTypeOfContract = newmobileTypeOfContract; 
    } 
    //Mutator for chargeUp 
public void setchargeUp(int chargeUp) 
    { 
this.chargeUp = chargeUp; 
    } 
    //Mutator to simulate using phone for a period of time 
public void switchedOnFor(int switchedOnFor) 
    { 
this.switchedOnFor = switchedOnFor; 
    } 
    //Accessor for type of phone 
public String getType() 
    { 
return phonetype; 
    } 
    //Accessor for provider 
public String getprovider() 
    { 
return mobileServiceProvider; 
    } 
    //Accessor for contract type 
public int getContractType() 
    { 
return mobileTypeOfContract; 
    } 
    //Accessor for charge 
public int getCharge() 
    { 
return chargeUp; 
    } 
    //Accessor which checks the phones remaining charge 
public int checkCharge() 
    { 
return checkCharge; 
    } 
    // simulates changing the provider 
public void changeProvider() 
    { 
provider = changeProvider; 
    } 
//returns the amount of change due for orders of mobiles. 
public int getBalance() 
    { 
return balance; 
    } 
    // A method to display the state of the object to the screen 
public void displayMobileDetails() { 
System.out.println("phonetype: " + phonetype); 
System.out.println("screensize: " + screensize); 
System.out.println("memorycardcapacity: " + memorycardcapacity); 
System.out.println("cameraresolution: " + cameraresolution); 
System.out.println("GPS: " + GPS); 
System.out.println("mobileServiceProvider: " + mobileServiceProvider); 
System.out.println("mobileTypeOfContract: " + mobileTypeOfContract); 
} 

     /** 
* The mymobile class implements an application that 
* simply displays "new Mobile!" to the standard output. 
*/ 
public class mymobile { 
public void main(String[] args) { 
System.out.println("new Mobile!"); //Display the string. 
    } 
} 
public static void buildPhones(){ 
Mobile Samsung = new Mobile("Samsung",3,4,"verizon",8,12,"GPS",100,25,"giffgaff"); 
Mobile Blackberry = new Mobile("Samsung",3,4,"verizon",8,12,"GPS",100,25,"giffgaff");  
}  
public static void main(String[] args) { 
buildPhones(); 
} 

} 

任何答复或答复和帮助,将不胜感激,因为我不能让它编译喜欢它,没有语法错误以前那样。

+3

错误的哪部分你不明白?你认为这条线有什么作用? (提示:你做了一个简单的类型,你应该能够发现) – SLaks

+0

在'return'和'phonetype'之间放置一个空格:'返回phonetype;'。看起来你需要在很多地方这样做。 – rgettman

+0

...当然对于所有getter从getType到checkCharge都是一样的...... – ppeterka

回答

1

添加一个空格return和变量名phonetype之间:

return phonetype; 

PS。有这个问题的不止一个在你的代码

+0

对不起,现在给我一个错误:方法获得平衡已经定义在类Mobile,在线142:public int getBalance() – user2909016

+0

那是因为你定义了它两次,删除其中一个:) – Craig

0

有在代码中的许多问题:

缺少空格:

return phonetype; 

缺少的成员变量:

private int balance; 

    public int getBalance() 
    { 
return balance; 
    } 

也有看起来像一条线:

public void setchargeUp(int chargeUp) 
{ 
chargeUp = chargeUp;  
} 

没有错误,但该方法没用,因为您只需更改局部变量,则应使用this.chargeUp来使用成员值。

+0

再次抱歉家伙,现在给我一个错误:无法找到符号变量价格,在第56行:退货价格; – user2909016