我有一个ArrayLists实现的问题 - 我尝试打印我的对象,但现在它只打印内存地址。我认为循环以某种方式是我的救星,但不能为了...的爱...弄清楚如何循环我的课程对象来实现这一目标。我错过了什么?这不可能是不可能的或任何事情,只是我要愚蠢地想出来(我的额头现在已经是我的键盘的永久印记)。返回ArrayList和打印对象
public class Course{
private String courseID;
private String courseName;
private int ap;
private static ArrayList<Course> courses = new ArrayList<Course>();
public static void main(String[] args) {
Course programmeringGrund = new Course ("725G61", "Programmering Grundkurs", 6);
Course itProjekt = new Course ("725G62", "IT-Projektledning - introduktion", 12);
Course diskretMatematik = new Course ("764G06", "Diskret Matematik och Logik", 6);
Course informatikTeknik = new Course ("725G37", "Informatik, teknik och lärande", 6);
System.out.println(getCourses());
} public Course (String aCourseID, String aCourseName, int anAp){
this.courseID=aCourseID;
this.courseName=aCourseName;
this.ap=anAp;
courses.add(this);
} public static List getCourses(){
return courses;
}
重写'Course'类中的'toString'方法。 –