I created a program with a new class called Student that sets and gets different variables such as name, GPA, if they are enrolled and when they are enrolled (this is a String, it is intended to be). The problem is that when I try to store the information into an array and/or array list and print it I get the hash code printed instead of the information. The program is not entirely complete, but I am trying to address the hash code issue first. If you could assist I would much appreciate. Thank you in advance!
Student st = new Student();
System.out.println(st.getName());
Student1();
Student st1 = new Student("John");
}
public static void Student1() {
System.out.println("Enter the data for student 1 :");
Student st = new Student();
Scanner keyboard = new Scanner(System.in);
String name = keyboard.next();
double GPA = keyboard.nextDouble();
boolean enrolled = keyboard.nextBoolean();
String date = keyboard.next();
for (int i =0; i<5; i++){
Student newStudent = new Student();
newStudent.setName(name);
newStudent.setGPA(GPA);
newStudent.setEnrolled(enrolled);
newStudent.setDate(date);
ArrayList <Student> strList = new ArrayList<Student>();
Student student[] = new Student[5];
newStudent.getName();
student[i] = newStudent;
strList.add(newStudent);
System.out.println(student[i]);
}
Student Class
public class Student {
private String name;
private double gpa;
private boolean enrolled;
private String enrollDate;
public Student() {
this.name = "";
this.gpa = 0.0;
this.enrolled = false;
this.enrollDate = "none";
}
public Student(String name1) {
this.name = name1;
this.gpa = 0.0;
this.enrolled = false;
this.enrollDate = "none";
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setGPA(double gpa) {
this.gpa = gpa;
}
public double getGPA() {
return this.gpa;
}
public void setEnrolled(boolean enrolled) {
this.enrolled = enrolled;
}
public boolean getEnrolled() {
return this.enrolled;
}
public void setDate(String date) {
}
}