2013-10-20 69 views
0

我想让我的代码创建我需要创建一个手机对象的新构造函数对象。我尝试命名构造函数字段来创建对象。Java错误 - 不是一个声明,这是什么意思?

当我编译我的代码在这一行this.Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS");我得到这个错误:不是一个声明,这是什么意思?

更新代码!

我的代码:

/** 
* to write a simple java class Mobile that models a mobile phone. 
* 
* @author (Lewis Burte-Clarke) 
* @version (14/10/13) 
*/ 
public class Mobile 

{ 
    // type of phone 
    private String phonetype; 
    // size of screen in inches 
    private int screensize; 
    // menory card capacity 
    private int memorycardcapacity; 
    // name of present service provider 
    private String serviceprovider; 
    // type of contract with service provider 
    private int typeofcontract; 
    // camera resolution in megapixels 
    private int cameraresolution; 
    // the percentage of charge left on the phone 
    private int checkcharge; 
    // wether the phone has GPS or not 
    private String GPS; 
    // instance variables - replace the example below with your own 
    private int x; 

    // The constructor method 

    public Mobile(String mobilephonetype, int mobilescreensize, 
      int mobilememorycardcapacity,int mobilecameraresolution,String mobileGPS, String newserviceprovider) { 
     this.phonetype = mobilephonetype; 
     this.screensize = mobilescreensize; 
     this.memorycardcapacity = mobilememorycardcapacity; 
     this.cameraresolution = mobilecameraresolution; 
     this.GPS = mobileGPS; 
     this.serviceprovider = newserviceprovider; 
     this.typeofcontract = 12; 
     this.checkcharge = checkcharge; 
     // you do not use this ones during instantiation,you can remove them if you do not need or assign them some default values 


     Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
     1024 = screen size; 
     2 = memory card capacity; 
     3=resolution; 
     GPS = gps; 
     "verizon"=service provider; 
     typeofcontract = 12; 
     checkcharge = checkcharge; 

    } 


    } 

    // 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("serviceprovider: " + serviceprovider); 
     System.out.println("typeofcontract: " + typeofcontract); 

    } 



} 

class mymobile { 
    public static void) { 
     Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
     Mobile Blackberry = new Mobile("Blackberry", "3.", "4","8", "GPS"); 
     Samsung.displayMobileDetails(); 
     Blackberry.displayMobileDetails(); 
    } 
} 

任何答复和答复将不胜感激!

+1

'this.Mobile'没有意义。 – SLaks

+0

报告的错误是什么? – pburka

+0

你认为这条线有什么作用? '这个。“verizon”=服务提供商;' – pburka

回答

0
Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS"); 

参数值3后缺少一个逗号。我会说这是你的罪魁祸首。

0

它的编译错误,这意味着编译器要求的声明,你给了别的东西,请refer

应该

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
1
this.2 = memory card capacity; 
this.3=resolution; 

毫无意义可言。

您不能将值分配给文字(2,3)。


编辑:您还需要解决这个问题:

Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 

正如其他成员说。

0

Mobile是一个类,“这”代表当前object.So,您不能使用“本”为Mobile.You应:

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
0
Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
    1024 = screen size; 
    2 = memory card capacity; 
    3=resolution; 
    GPS = gps; 
    "verizon"=service provider; 
    typeofcontract = 12; 
    checkcharge = checkcharge; 

您需要更换号码你的new Mobile ctor调用具有合理的价值,如下面必须注释/注释所描述的,例如,如果你有一个1放在决议中(这是没有意义的,除非它是索引或什么的),你有一个2放在存储卡容量,其中有3放入分辨率等

然后注释掉垃圾的行,或者最好删除它们。