0

携帯電話オブジェクトを作成するために必要な新しいコンストラクタ オブジェクトをコードで作成しようとしています。オブジェクトを作成するために、コンストラクタ フィールドに名前を付けようとしました。

この行でコードをコンパイルすると、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();
    }
}

回答と返信をいただければ幸いです。

4

5 に答える 5

0

Mobile はクラスです。"this" は現在のオブジェクトを表します。そのため、"this" を Mobile に使用することはできません。次のことを行う必要があります。

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS");
于 2013-10-20T03:11:26.633 に答える
0
Mobile Samsung = new Mobile("Samsung", 1, 2, "verizon", 3 "GPS");

パラメータ値 3 の後にカンマがありません。それが原因だと思います。

于 2013-10-20T02:59:17.640 に答える
0

これはコンパイル エラーです。つまり、コンパイラがステートメントを予期していたのに、別のステートメントを指定したことを意味します。参照してください。

する必要があります

Mobile samsungPhone = new Mobile("Samsung", 1, 2, "verizon", 3, "GPS"); 
于 2013-10-20T03:00:10.023 に答える
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方、解像度の入れ方など。

次に、不要な行をコメントアウトするか、できれば削除します。

于 2013-10-20T04:01:42.597 に答える