Java programming help? (Code included) I attached the instructions in the question here and I will include my code in the comments. Note that I have already finished the Course program, but the code I am entering in the comments is for Student. I did that one but I was experiencing errors at the end of the program. Tester was hard to do. Thanks.
Student code: public class Student{ private String studentName; private Course[] allCourses; public void setName(String name){ this.studentName = name; } public void setAllCourses(Course[] allCourses){ this.allCourses = allCourses; } public String getName(){ return studentName; } public Course[] getAllCourses(){ return allCourses; } public Student(){ this.studentName = ""; this.allCourses = new Course[1]; } public Student(String name){ this.studentName = name; this.allCourses = new Course[4]; } public Student(String name, Course[] c){ this.studentName = name; allCourses = c; } public int getTotalCreditHours(){ int total = 0; for(int i=0; i<allCourses.length; i++){ total += allCourses[i].getCreditHours(); } return total; } public void print(){ System.out.println(studentName + " " + getTotalCreditHours() + "hrs"); for(int i=0; i<allCourses.length; i++){ System.out.println(allCourses[i].getCourseTitle()); } return total; } }
Course program: public class Course{ private String courseNumber; private String courseTitle; private int creditHours; public void setCourseNumber(String courseNumber){ this.courseNumber = courseNumber; } public void setCourseTitle(String courseTitle){ this.courseTitle = courseTitle; } public void setCreditHours(int creditHours){ this.creditHours = creditHours; } public String getCourseNumber(){ return courseNumber; } public String getCourseTitle(){ return courseTitle; } public int getcreditHours(){ return creditHours; } public Course(){ this.courseNumber = ""; this.courseTitle = ""; this.creditHours = 0; } public Course(String courseNumber, String courseTitle, int creditHours){ courseNumber = courseNumber; courseTitle = courseTitle; creditHours = creditHours; } }
Errors in Student program: public void print(){ System.out.println(studentName + " " + getTotalCreditHours() + "hrs"); for(int i=0; i<allCourses.length; i++){ System.out.println(allCourses[i].getCourseTitle()); } return total; }
that's not an error, it's code
Join our real-time social learning platform and learn together with your friends!