2013-10-20 3 views
0

휴대 전화 개체를 만드는 데 필요한 새 생성자 개체를 만들려면 코드를 가져 오려고합니다. Constructor 필드의 이름을 지정하여 객체를 만들려고했습니다.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

이 행에서 무엇을 기대합니까? "this."verizon "= service provider; – 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"); 

를 다른 회원들에 의해 언급 한 바와 같이. 당신의 숫자를 교체해야

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

모바일은 "이"현재 object.So 위해 서, 당신은 "이"Mobile.You 정상적으로 사용할 수없는 클래스이다 귀하의 new Mobile은 적절한 값으로 전화를 걸었습니다. 아래의 주석/참고 사항이 있어야합니다. 예를 들어 1이 어디에 있는지 (예 : 색인을 생성하지 않으면 의미가 없음) 2 메모리 카드 용량, 해상도에 넣어 3 등.

그런 다음 가비지 인 행을 주석 처리하거나 선호하는 행을 삭제하십시오.

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; 

:

관련 문제