Thank you so much!!
My assignment was to create 5 classes: Instructor, Student, Course, Section, and a class, which I named Testing01, to house the main method. I had no problem with this part.
The second part was to create an Instructor object, a Course object, and an Student object with 15 student names. I also needed to have these objects displayed. I accomplished the student list with the PrintWriter() function (since we hadn't learned arrays, yet).
The third part was to create the ArrayList() for the students and another List for the grades, having the program display the two ArrayLists (I do realize I could have done a two-dimensional ArrayList).
At this point, I had the four classes with getters and setters, and the fifth class with the main method. I created the new objects like this:
Code: Instructor inst = new Instructor ("George Jones");
Course crse = new Course ("Java Programming");
and then the ArrayList like this:
Code: ArrayList<String> students = new ArrayList<String>();
Next, I added the student names using the ArrayList.add method (I could make it two dimensional to add the grade list as well). I also used a for loop to cycle through the list of names:
Code: for (int i = 0; i < students.size(); i++){
// Instantiation of Student class
Student stdt = new Student();
stdt.setFullName(students.get(i));
stdt.setLevel(grades[i]);
// Print the current value of the variable
System.out.printf("%s\t\t%s\n", stdt.getFullName(), stdt.getLevel());
}
That was what I handed in as my assignment. I received this as feedback:
Quote:
You're pretty close on this one. You have the modeling down up to the section and then you made things a little too hard on yourself. Take a look at the Section class that I posted in the discussion this week. You can use this Section class to make an object that has a course, instructor and roster of students. That is a much more sensible place to bring the elements together and then you just have the main method be an exercise of instantiating the Section object and populating it and then printing its values. This is a good effort, though.
His Section class looks like this:
Code:
import java.util.ArrayList;
public class Section {
private Course course;
private Instructor instructor;
private ArrayList<Student> students;
public Section() {
super();
}
public Section(Course course) {
}
public Section(Course course, Instructor instructor) {
}
public Section(Course course, Instructor instructor, ArrayList<Student> students) {
}
// getters and setters
public void setCourse(Course course)
{
this.course = course;
}
public Course getCourse()
{
return course;
}
public void setInstructor(Instructor instructor)
{
this.instructor = instructor;
}
public Instructor getInstructor()
{
return instructor;
}
public void setStudents(ArrayList<Student> students)
{
this.students = students;
}
public ArrayList<Student> getStudents()
{
return students;
}
public void addStudent(Student student)
{
students.add(student); // add a student to the section roster
}
}
I can't find anything in my reading about how to create a Section object with an Instructor object, Course object, and a student ArrayList object.
Could anyone help me to understand this kind of a process or maybe even walk me through the steps? I will be so grateful!