2013-10-19 1 views
0

휴대 전화 개체를 만드는 데 필요한 새 생성자 개체를 만들려면 코드를 가져 오려고합니다. Constructor 필드의 이름을 지정하여 객체를 만들려고했습니다.Java 오류, 기호 - 클래스 문자열을 찾을 수 없습니다.

UPDATE :

public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution, 
     String MobileGPS) { 
:

error: constructor Mobile(java.lang.String,int,int,java.lang.String,int,java.lang.String) is already defined in class Mobile 

이 오류가있는 페이지의 하단에 온다 : 나는 그러나 지금은 그것을 업데이트 할 때 나는 오류, Stringstring을 개정 한

이 오류는 무엇을 의미합니까?

지금까지 코드 :

/** 
* 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, String newserviceprovider, int mobileCameraResolution, 
      String mobileGPS) { 
     this.phonetype = mobilePhonetype; 
     this.screensize = mobileScreensize; 
     this.memorycardcapacity = mobileMemoryCardCapacity; 
     this.cameraresolution = mobileCameraResolution; 
     this.GPS = mobileGPS; 

     // you do not use this ones during instantiation,you can remove them if you do not need or assign them some default values 
     this.serviceprovider = newserviceprovider; 
     this.typeofcontract = 12; 
     this.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); 

    } 

    public Mobile(String MobilephoneType, int Mobilescreensize, int Mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution, 
      String MobileGPS) { 
     this.phonetype = Mobilephonetype; 
     this.screensize = 3; 
     this.memorycardcapacity = 4; 
     this.cameraresolution = 8; 
     this.GPS = GPS; 
     this.serviceprovider = newserviceprovider; 
     this.typeofcontract = 12; 
     this.checkcharge = checkcharge; 


    } 

} 

class mymobile { 
    public static void main(String[] args) { 
     Mobile Samsung = new Mobile("Samsung", "3", "4", "8", 
       "GPS"); 
     Mobile Blackberry = new Mobile("Blackberry", "3.", "4", 
       "8", "GPS"); 
     Samsung.displayMobileDetails(); 
     Blackberry.displayMobileDetails(); 
    } 
} 
+1

오류 "생성자의 이동은 (java.lang.String의, INT, INT, java.lang.String의, INT, java.lang.String의) 이미 클래스 모바일에서 정의는"정확히 무엇을 의미 그것은 말한다. 동일한 서명을 가진 두 개의 생성자가 있습니다. 중복 된 생성자 중 하나만 삭제하십시오. – pburka

+0

새로운 질문이있는 경우 새로운 질문을하십시오. 하나의 질문을 편집하여 다른 질문으로 바꾸지 마십시오. 그렇지 않으면 스택 오버플로가 질문에 고착되고 일부는 대답과 맞지 않습니다. ... 그리고 컴파일러 오류는 정확히 무엇을 말합니다. 이러한 매개 변수를 가진 생성자를 이미 얻었 으면 생성자'Mobile (String, int, int, String, int, String) '을 정의하고 있습니다. –

답변

4

자바는 대소 문자를 구분합니다. 항상 대문자로 시작 (일명 유형을 참조) String

private String phonetype; 

개체 이름을 대문자 S를 사용합니다. 핵심 클래스는 오라클의 명명 규칙을 따릅니다. 그 here

6

string 읽기에 대한 당신은 자바는 대소 문자를 구분 s

private String phonetype; 

소문자로 문자열 유형이 S.을 대문자로해야한다. String은 Object 클래스에서 확장되는 클래스이므로 Integer처럼 대문자로 된 것입니다. 그러나 프리미티브 유형은 자본화되지 않습니다 (즉, boolean, int, char).

0

문자열을 대문자로 만드십시오. 그것은 감각적 인 케이스입니다.

http://docs.oracle.com/javase/7/docs/api/java/lang/String.html

+0

UPDATE가 수정되어 String에서 대문자 S로 변경되었습니다. 그러나 업데이트 할 때 오류가 발생합니다. 생성자 모바일 (java.lang.String, int, int, java.lang.String, int, java.lang.String)은 이미 오류가 페이지 하단에 표시됩니다. public Mobile (String MobilephoneType, int Mobilescreensize, int mobilememorycardcapacity, String newserviceprovider, int Mobilecameraresolution, String MobileGPS) { 이게 무슨 뜻입니까 ?? – user2898828

+0

정확히 두 개의 유사한 생성자가 있습니다. 게시 한 코드에서 59-71 행을 제거하십시오. 그리고 모바일 개체를 만들 때 정수는 문자열로 전달되지 않습니다. 따라서 따옴표를 제거하십시오. 값은 생성자에 입력 한 값과 일치해야합니다. 따라서 모바일 객체를 만들 때 생성자에 나열된 것과 동일한 순서로 매개 변수를 제공해야합니다. 모바일 samsungPhone = 새 모바일 ("삼성", 1, 2, "verizon", 3 "GPS"); 1024 = 화면 크기, 2 = 메모리 카드 용량, "verizon"= 서비스 공급자, 3 = 해상도 및 "GPS"= gps. – CamHart

관련 문제