I have two classes. Student and StudentTest.
My test class wil read the student info from the command line. I also need to check if the student already exists with equals() method. Can someone help me with this?
Student
public class Student {
private String firstName;
private String lastName;
private String studentNumber;
Student(String fName,String lName,String sNumber)
{
firstName=fName;
lastName=lName;
studentNumber=sNumber;
}
public Student()
{
}
public void setFirstName(String fName)
{
firstName=fName;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String lName)
{
lastName=lName
}
public String getLastName()
{
return lastName;
}
public void setStudentNumber(String sNumber)
{
studentNumber=sNumber;
} public String getStudentNumber()
{
return studentNumber;
}
public String toString() {
return String.format("%-8s %-9s %-8s\n",firstName,lastName,studentNumber );
}
}
//StudentTest
import java.util.Scanner;
public class StudentTest {
public static void main( String[] args)
{
Student[] students = new Student[2];
Scanner inputs = new Scanner(System.in);
for(int i = 0 ; i < students.length; i++)
{
System.out.println("Please enter Student Number");
String fName = inputs.nextLine();
System.out.println("Please enter Student First Name");
String lName = inputs.nextLine();
System.out.println("Please enter Student Last Name");
String sNumber = inputs.nextLine();
students[i] = new Student(fName, lName, sNumber);
}
for(int i = 0 ; i < students.length; i++)
{
System.out.print(students[i].toString());
}
}
}