I have some java book and i’m doing exercises. But right now i’m stuck on exercises associated with arrays. i have following exercise:
Create a CollegeCourse class. The class contains fields for the course ID (for example,
“CIS 210”), credit hours (for example, 3), and a letter grade (for example, ‘A’).Include get() and set()methods for each field. Create a Student class containing an
ID number and an array of five CollegeCourse objects. Create a get() and set()
method for the Student ID number. Also create a get() method that returns one
of the Student’s CollegeCourses; the method takes an integer argument and
returns the CollegeCourse in that position (0 through 4). Next, create a set()
method that sets the value of one of the Student’s CollegeCourses; the method
takes two arguments—a CollegeCourse and an integer representing the
CollegeCourse’s position (0 through 4).
I already did data fields and id’s and getters from student class. But right now i’m a little confused with this:
Also create a get() method that returns one
of the Student’s CollegeCourses; the method takes an integer argument and
returns the CollegeCourse in that position (0 through 4). Next, create a set()
method that sets the value of one of the Student’s CollegeCourses; the method
takes two arguments—a CollegeCourse and an integer representing the
CollegeCourse’s position (0 through 4).
Can anyone point me to the right direction how to resolve this. Because it’s array chapter i think it must be resolved doing arrays? Any help would be appreciated.
EDIT: ok here is my CollegeCourse Class
public class CollegeCourse {
String courseID;
int creditHours;
char grade;
public void setCourseId(String id) {
this.courseID = id;
}
public String getCourse() {
return courseID;
}
public void setHours(int hours) {
this.creditHours = hours;
}
public int getHours() {
return creditHours;
}
public void setGrade(char grade) {
this.grade = grade;
}
}
and here is my student class ( im stuck here):
public class Student {
int id;
CollegeCourse[] cc = new CollegeCourse[5];
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setCollegeCourse(CollegeCourse course, int position) {
// i'm stuck here
}
}
Basically its asking you to create a getter/setter for contents of the array;