Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Course that represents a course taken at a school. Represent each student using the Student class. Use an array in the

Write a class called Course that represents a course taken at a school. Represent each student using the Student class. Use an array 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.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Student Class: Modify the Student class that might be part of a school system as follows:

Static Class Constants

Define a public int value like NUM_TESTS set it to 3. int NUM_TESTS = 3;

Private Member Data

Each student object should also contain the scores for three tests. int test1, test2, test3; boolean errorFlag;

Constructors

Provide a constructor that sets all instance values based on parameter values. Because we have the errorFlag member, the constructor (via the mutator), can set that member when it gets bad data.

Overload the constructor such that each test score is assumed to be initially zero.

Public Methods

Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score.

Also, provide a method called getTestScore that accepts the test number and returns the appropriate score.

Provide a method called average that computes and returns the average test score for this student.

Modify the toString method such that the test scores and average are included in the description of the student. If errorFlag == true, it should return correspondingly reasonable reflection of this fact (something like "invalid ").

No mutator for errorFlag.

Provide a method called equals returns true if the first name, last name, and three scores (members) are identical; false if otherwise. method header: boolean equals(Student student)

getters and setters

Private Methods

Provide a static helper method that returns true or false, depending on the legality of the parameters method header: boolean static isValid(int testNumber, int score)

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Course Class: Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class.

Static Class Constants

Define a public int value like MAX_STUDENTS and set it to something like 30 or 40. int MAX_STUDENTS = 40;

Private Member Data

Use an array to store the students taking that course. Student[] studentList;

String courseName;

int numStudents;

Constructors

The constructor of the Course class should accept only the name of the course.

Course() - a default constructor. Public Methods

Provide a method resetCourse() that removes all students from the course(in the simplest way).

Provide a method called addStudent that accepts one Student parameter and adds a student to the next available position in the studentList array if the parameter is an error-free Student object and if there is room in the Course object for another student (according to MAX_STUDENTS). It returns false if the Course was full. If there is room for a student, add the student to the roster method header: public boolean addStudent(Student student)

Provide a method called dropStudent that accepts one Student parameter. if the student is on the roster, remove them. method header: public boolean dropStudent(Student student)

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. include the name, number of students enrolled in the course, the maximum number that can be enrolled, and a printed roster as part of the text representation.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Driver Class: Create a driver class School.java with a main method that creates a course, adds several students, drops a student, prints a roll, and prints the overall course test average.

Notes:

You can include additional instance data variables if it is helpful. If you include additional variables, then also include additional getters and setters as appropriate.

You might add additional code to the driver to run additional tests to ensure your classes work.

Ensure that the roster does not print any "nulls."

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//******************************************************************** // Student.java // // Represents a college student. //********************************************************************

public class Student { private String firstName, lastName; private Address homeAddress, schoolAddress;

//----------------------------------------------------------------- // 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; }

//----------------------------------------------------------------- // Returns a string description of this Student object. //----------------------------------------------------------------- public String toString() { String result;

result = firstName + " " + lastName + " "; result += "Home Address: " + homeAddress + " "; result += "School Address: " + schoolAddress;

return result; } }

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//******************************************************************** // Address.java // // Represents a street address. //********************************************************************

public class Address { private String streetAddress, city, state; private long zipCode;

//----------------------------------------------------------------- // Constructor: Sets up this address with the specified data. //----------------------------------------------------------------- public Address(String street, String town, String st, long zip) { streetAddress = street; city = town; state = st; zipCode = zip; }

//----------------------------------------------------------------- // Returns a description of this Address object. //----------------------------------------------------------------- public String toString() { String result;

result = streetAddress + " "; result += city + ", " + state + " " + zipCode;

return result; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

how do i do this in good form second picture is same problem

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago