package studentclient;
import java.util.Scanner;
public class StudentClient {
public static void main(String[] args) {
/* Declare two object references of type Student s1 and s2 and instantiate two Student objects passing three arguments to the constructor for the class. Use different values for each class object */
Student s1 = new Student("Dick Grayson", "666-66-6666", 3.80);
Student s2 = new Student("Jason Todd", "666-77-7777", 3.50);
Scanner scan = new Scanner(System.in);
/* Output the name, social security number and GPA of the student from object reference s1 using the appropriate accessor methods(Get methods) to obtain the data */
System.out.println("Student Information");
System.out.println("Student Name: " + s1.getName());
System.out.println("Student Social Security Number: " + s1.getSsn());
System.out.println("Student GPA: " + s1.getGpa());
/* Output the name, social security number and GPA of the student from object reference s2 using the toString method to return the data */
System.out.println("Student Information");
System.out.print(s2);
/* Using the equals method and a selection control structure (if statement), compare objects s1 and s2 and output an appropriate message indicating if the objects are equal */
if(s1.equals(s2)){
System.out.println("Student's identities are equal!");
}else {
System.out.println("Student's identities are not equal!");
}
/* Using the appropriate mutator methods(Set Methods) on student object s2, change the name, social security number and GPA to the same values as in object s1. Use the set methods. */
System.out.println("Enter new Student Information for Student 2: ");
s2.setName("Dick Grayson");
System.out.println("Student Name: " + s2.getName());
s2.setSsn("666-66-6666");
System.out.println("Student Social Security Number: " + s2.getSsn());
s2.setGpa(3.80);
System.out.println("Student GPA: " + s2.getGpa());
/* Again, using the equals method and a selection control structure (if statement), compare objects s1 and s2 and output an appropriate message indicating if the objects are equal */
if(s1.equals(s2)){
System.out.println("Student's identities are equal!");
}else{
System.out.println("Student's identities are not equal!");
}
}
}
問題是,對於第二組信息s2顯然等於s1,不平等。我該怎麼辦? 當我運行它,我得到這些結果我是編程新手,我不知道是否因爲我的語法而發生此錯誤
學生信息 學生姓名:迪克·格雷森 學生的社會安全號碼:666-66-6666 學生GPA:3.8 學生信息 名稱:傑森·託德 社會安全號碼: 666-77-7777 GPA:3.5 學生的身份不相同! 爲學生2輸入新的學生信息: 學生姓名:Dick Grayson 學生社會安全號碼:666-66-6666 學生GPA:3.8 學生的身份不相同! BUILD SUCCESSFUL(總時間:0秒)
小心妥善格式化您的問題。 [如何問](https://stackoverflow.com/help/how-to-ask) –
也許你想發佈[**最小**,完整和可驗證的例子](https://stackoverflow.com /幫助/ MCVE)。 – khelwood
問題在於學生的等值方法 –