13
I need to be able to print out the Student objects(all variables) in my array list. Is this possible? When i try to print it outputs this sort of thing e.g student.Student@82701e. I think it's hexadecimal or something
This is my code:
package student;
public class Student {
private String studentName;
private String studentNo;
private String email;
private int year;
public Student() {
this.studentName = null;
this.studentNo = null;
this.email = null;
this.year = -1;
}
public Student(String nName, String nNum, String nEmail, int nYr) {
this.studentName = nName;
this.studentNo = nNum;
this.email = nEmail;
this.year = nYr;
}
public void setStudentName(String newStudentName) {
this.studentName = newStudentName;
}
public void setStudentNo(String newStudentNo) {
this.studentNo = newStudentNo;
}
public void setEmail(String newEmail) {
this.email = newEmail;
}
public void setYear(int newYear) {
this.year = newYear;
}
public String getStudentName() {
return studentName;
}
public String getStudentNo() {
return studentNo;
}
public String getEmail() {
return email;
}
public int getYear() {
return year;
}
}
package student;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class studentTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
List<Student> Students = new ArrayList();
Student student1 = new Student();
student1.setStudentName("Bob Marley");
student1.setStudentNo("N0002");
student1.setEmail("student2@student.com");
student1.setYear(2);
Students.add(student1);
Student student2 = new Student();
student2.setStudentName(