167k views
3 votes
Design and implement a class called Course that represents a course taken at a school. The Course class should track up to five students using the modified Student class from a previous programming project. The Course constructor should accept only the name of the course. This class should include:

1. A method called addStudent that accepts one Student parameter (the Course object should keep track of the number of valid students added to the course).
2. A method called average that calculates and returns the average of all students’ test score averages.
3. A method called roll that prints all students in the course.

Create a driver class with a main method that accomplishes the following:
a) Create a course.
b) Add several students to the course.
c) Print the roll of students.
d) Print the overall course test average.

1 Answer

5 votes

Final answer:

A Course class tracks up to five students and includes methods for adding students, calculating test score averages, and printing a roll. A driver class would manage these functionalities.

Step-by-step explanation:

Designing the Course Class:

To achieve the objectives of the student's request, we will define a Course class in a programming language. This class will have the ability to add students, calculate average test scores, and print a roll of the students. A sample implementation in a language like Java might look like the following:

class Student {
// Student details not shown
double getAverageTestScore() { /* Method to return the average test score */ }
}

class Course {
private String courseName;
private Student[] students;
private int studentCount;

public Course(String name) {
this.courseName = name;
this.students = new Student[5];
this.studentCount = 0;
}

public void addStudent(Student student) {
// Code to add a student to the course
}

public double average() {
// Code to calculate the average of all students’ test score averages
return 0; // Placeholder return
}

public void roll() {
// Code to print all students in the course
}
}

Furthermore, a driver class would be responsible for creating a course, adding students, printing the roll, and printing the course test average as requested.

User Trond Nordheim
by
8.2k points