Question: School Class: public class School { private String name; private int numberOfStudents; public School(String name, int numberOfStudents) { this.name = name; this.numberOfStudents = numberOfStudents; }

School Class:

public class School { private String name; private int numberOfStudents; public School(String name, int numberOfStudents) { this.name = name; this.numberOfStudents = numberOfStudents; } public School(String name) { this.name = name; this.numberOfStudents = 0; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNumberOfStudents() { return numberOfStudents; } public void setNumberOfStudents(int numberOfStudents) { if(numberOfStudents < 0) { numberOfStudents = 0; } this.numberOfStudents = numberOfStudents; } @Override public String toString() { return String.format("Name: %s Number of students: %d", name, numberOfStudents); } }

In the next questions, write a complete class definition for a class called HighSchool, which is a child class of the School class you just wrote.

A HighSchool is described by its name, the number of students in the school, and whether or not the school is a specialized school (e.g., a science magnet school or a performing arts school).

Use good principles of class design, encapsulation, and inheritance. Reuse code whenever possible.

Question 1

Write the class header and the instance data variables for the HighSchool class.

Question 2

Write one constructor that sets the name, number of students, and whether or not the school is specialized based on parameters

Question 3

Write appropriate getter/setter methods. Include validity checks where appropriate.

Question 4

Write a toString method that generates a text representation using the following formatting.

Name: Clark High School

Number of students: 947

Specialized: true

Question 5

Write an equals method for the HighSchool class. Two high schools are logically equivalent if they have the same name (ignoring capitalization), number of students, and specialization status.

Question 6

Have the HighSchool class implement the Comparable interface.

Write the new class header.

Write the full compareTo method. High schools are compared/ordered first by name and then by the number of students.

Question 7

Write code that would go inside of a main method.

Creates an array of 5 School objects that contains some School and some HighSchool objects.

Use a loop to print a text representation of each object.

Use a loop and polymorphism to count the number of high schools that are specialized.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!