我创建了一个程序,其中包含一个名为 Student 的新类,该类设置和获取不同的变量,例如姓名、GPA、是否注册以及何时注册(这是一个字符串,它应该是)。问题是当我尝试将信息存储到数组和/或数组列表中并打印它时,我得到的是哈希码而不是信息。该程序并不完全完整,但我试图首先解决哈希码问题。如果您能提供帮助,我将不胜感激。先感谢您!
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]);
}
学生班
公共课学生{
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) {
}
}