Question
Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class from the previous programming
Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class from the previous programming project. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called average that computes and returns the average of all students test score averages. Provide a method called roll that prints all students in the course. Create a driver class with a main method that creates a course, adds several students, prints a roll, and prints the overall course test average.
THIS IS MY MODIFIED STUDENT CLASS
//******************************************************************** public class Student {
private String firstName, lastName; private Address homeAddress, schoolAddress; private TestScore testScores;
// ----------------------------------------------------------------- // Constructor: Sets up this student with the specified values. // ----------------------------------------------------------------- public Student(String first, String last, Address home, Address school) { firstName = first; lastName = last; homeAddress = home; schoolAddress = school; //Crate testScore with default test score of zero testScores = new TestScore(0, 0, 0); }
//Overloaded constructor public Student(String first, String last, Address home, Address school,int test1,int test2,int test3 ) { firstName = first; lastName = last; homeAddress = home; schoolAddress = school; //Crate testScore with given test scores testScores = new TestScore(test1, test2, test3); }
//Method to set test score public void setTestScore(int testNumber,int testScore) { if(testNumber==1) { testScores.setTest1(testScore); } else if(testNumber==2) { testScores.setTest2(testScore); } else if(testNumber==3) { testScores.setTest3(testScore); } } //Method to return test score by test number public int getTestScore(int testNumber) { if(testNumber==1) { return testScores.getTest1(); } else if(testNumber==2) { return testScores.getTest2(); } else if(testNumber==3) { return testScores.getTest3(); } else { return 0; } } //Method to get average test score public double getAverageTestScores() { double avg; avg = (testScores.getTest1() + testScores.getTest2() + testScores.getTest3())/3.0; return avg; } public String toString() { String result; result = "------------- "+firstName + " " + lastName + " ------------- "; result += "Home Address:" + homeAddress + " "; result += "School Address:" + schoolAddress+ " "; result += "Test 1 score:" + testScores.getTest1() + " "; result += "Test 2 score:" + testScores.getTest2() + " "; result += "Test 3 score:" + testScores.getTest3() + " "; result += "Average test score:" + getAverageTestScores() + " ";
return result; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started