프로그래밍이 처음인데 이름이라는 클래스를 쓰는 임무가 있습니다. 내 주요 방법으로, 전체 이름을 읽고 내 이름 생성자에게 전달하고 싶습니다. 그러나 메서드 데이터를 전달할 때 형식 불일치 오류가 계속 발생합니다. 내가 도대체 뭘 잘못하고있는 겁니까??자바에서 사용자 지정 데이터 형식 사용
import java.util.Scanner;
public class Names {
String first, middle, last;
/**
* @param args
*/
public Names(){
}
public Names(String first, String middle, String last){
first = this.first;
middle = this.middle;
last = this.last;
}
//returns the first name
public String getFirst(){
return first;
}
//returns the middle name
public String getMiddle(){
return middle;
}
//returns the last name
public String getLast(){
return last;
}
// Returns a string containing the person's full name in order,
public String firstMiddleLast(){
String ret = first + " " + middle + " " + last;
return ret;
}
public String lastFirstMiddle(){
String ret = last + ", " + first + " " + middle;
return ret;
}
public boolean equals(Names otherName){
if (first.equalsIgnoreCase(otherName.first) || middle.equalsIgnoreCase(otherName.middle)
|| last.equalsIgnoreCase(otherName.last))
return true;
else
return false;
}
public String initials(){
String retVal = first.substring(0) + "." + middle.substring(0) + "." + last.substring(0) + ".";
return retVal.toUpperCase();
}
public int length(){
String wholeName = (first+middle+last);
int retVal = wholeName.length();
return retVal;
}
public static void main(String[] args) {
Names person1 = new Names();
Names person2 = new Names();
Scanner scan = new Scanner(System.in);
System.out.println("Enter First Name: ");
person1.first = scan.next();
}
}
먼저 this- this.first =처럼 사용; this.middle = middle; this.last = last; – KG2289
유형이 일치하지 않는 행이 있습니까? –
@KratikaG 부정확하지만 형식이 맞지 않습니다. –