私はプログラミングが初めてで、Names というクラスを作成する割り当てがあります。私のメイン メソッドでは、名前全体を読み取り、それを Names コンストラクターに渡したいと考えています。ただし、メソッド データを渡すときに型の不一致エラーが発生し続けます。私は何を間違っていますか??
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();
}
}