したがって、学校では、基本的なことを実際に説明することなく、Javaに移行しました。ブールメソッドの結果をメインメソッドで呼び出す方法
今私は、2つの名前が同じかどうかをテストするequalsTestメソッドを持つクラスがあるという問題があります。私の主な方法では、equalsTestの結果を呼び出す必要があります。名前が同じであれば同じ友達(equalsTest = true)、名前が異なる場合は(samealsTest = false)
public class Person {
/* Attribute declarations */
private String lastName; // last name
private String firstName; // first name
private String email; // email address
public Person(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
//there are a few other methods in here but are not necessary for the issue explained
public boolean equalsTest(Person other){
if (this.firstName.equals(other.firstName)&& this.lastName.equals(other.lastName))
return true;
else
return false;
public static void main (String[] args) {
// create a friend
Person friend1 = new Person("Mickey", "Mouse", "");
friend1.setEmail("[email protected]");
// create another friend
Person friend3 = new Person ("Mickey", "Mouse", "");
// create a friend without email
Person friend2 = new Person("Minnie", "Mouse", "");
//Here I need another method that calls the "true" or "false" boolean result of the equalsTest method above and says "if equalsTest true, print "Same Friend", and if equalsTest false, print "Not Same Friend", etc.
また、ラボの要件の1つは、equalsTestメソッドをCANTで編集できることです。メインメソッドで呼び出す必要があります。私はそれを分析するメインの方法でセクションを作るのは簡単かもしれないが、それを行うことはできません。
何を探してるんですか? 'friend2.equalsTest(friend3)'? – luk2302
説明したように、friend1がfriend2と等しい場合はtrueまたはfalseを返すメソッドがあります。最初のメソッドの結果を呼び出すために、別のメソッドのコードが必要です。結果がtrueの場合は、同じ友達 "になり、結果が偽であれば"同じではない友人 "をプリントアウト – MezyMinzy