Question
Java questions need help! There are two questions that related to each other. Q1. Write a complete class definition for a class called School. A
Java questions need help! There are two questions that related to each other.
Q1.
Write a complete class definition for a class called School.
A school is described by: a name and the number of students.
Use good principles of class design and encapsulation.
1.
Write the class header and the instance data variable for the School class.
2.
Write two constructors:
one constructor sets the name and number based on a parameters
a second constructor sets the name based on a parameter and uses the default value of being a school with 0 students
3.
Write appropriate getter/setter methods. Include validity checks where appropriate.
4.
Write a toString method that generates a text representation in the following format:
Name: Milton Elementary
Number of students: 400
Please answer each question separately and include question number.
Q2.
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.
1.
Write the class header and the instance data variables for the HighSchool class.
2.
Write one constructor that sets the name, number of students, and whether or not the school is specialized based on parameters
3.
Write appropriate getter/setter methods. Include appropriate validity checks.
4.
Write a toString method that generates a text representation using the following formatting.
Name: Clark High School
Number of students: 947
Specialized: true
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.
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.
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.
Please answer each question separately and include question number.
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