Question: use classes and inheritence For this assignment, you will create a hierarchy of five classes to describe various elements of a school setting. The classes
use classes and inheritence
For this assignment, you will create a hierarchy of five classes to describe various elements of a school setting. The classes you will write are: Person, Student,Teacher, HighSchoolStudent, and School. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task with this assignment.
Person
Variables:
String firstName - Holds the person's first name
String lastName - Holds the person's last name
Methods:
Person(String fName, String lName) - Constructor that takes in String parameters representing the first and last names
String toString() - Returns a String with the following format:
lastName, firstName
Student extends Person
Variables:
int studentId - Using a static variable to keep track of how many students there are, every student should be assigned a unique value for their own studentId.
int level - Represents a student's grade level with possible values ranging from 0 to 12, where 0 represents kindergarten.
Methods:
Student(String fName, String lName, int gLevel) - Constructor that accepts the first and last names and the student level. Student level should be assigned 0 if gLevel is not between 0 and 12 inclusive. The first and last names should be set by calling the constructor of the parent class. The Student constructor also sets the studentId to the next available positive integer. The first Student created should have a studentId of 1, the second will have an ID of 2, third of 3, etc.
int getLevel() - Returns the student's grade level.
String toString() - Returns a three line String with Student info formatted as follows:
Smith, Mary Grade Level: 2 ID #: 1 Note: there are three spaces before "Grade Level: ..." and "ID #: ...".
HighSchoolStudent extends Student
Variables:
double gpa - Stores a grade point average between 0 and 5 inclusive
Methods:
HighSchoolStudent(String fName, String lName, int gLevel, double gpa) - The first and last names and the level should be set by calling the constructor of the parent class. The GPA should be between 0 and 5 inclusive, otherwise set to 0.
String toString() - Returns a four line String with HighSchoolStudent info formatted as follows:
Lee, Sarah Grade Level: 9 ID #: 2 GPA: 3.7 Note: there are three spaces before "Grade Level: ...", "ID #: ..." and "GPA: ...".
Teacher extends Person
Variables:
String subject - A String representing the academic subject taught by the teacher.
Methods:
Teacher(String fName, String lName, String subject) - The first and last names should be set by calling the constructor of the parent class.
String toString() - Returns a two line String with Teacher info formatted as follows:
Dovi, Rebecca Subject: Computer Science Note: there are three spaces before "Subject: ...".
School
Variables:
ArrayList
ArrayList
Methods:
School(ArrayList
String getGradeLevel(int level) - Returns a String listing all the schools's students that are at the specified grade level. Returns an empty String if the school has no students at the specified level. See the Sample Run below for the format of the returned String.
String toString() - Returns a multiline String listing the teachers and students at the school. The String is formatted as follows:
Faculty: {listing of faculty, one on each line} Student Body: {listing of students, one on each line}
See the Sample Run below for an example.
Remember, all variables should have an access level of private and all required methods should have an access level of public. Wherever possible, the child class should use a call to the parent's toString and/or constructor methods.
Please download the runner class, student_runner_School.java and verify that the class output matches the sample run that follows. We will use a different runner to grade the program. Remember to change the runner to test different values to make sure your program fits the requirements.
Sample Run of student_runner_School.java:
printing person: Doe, John printing student: Smithers, Sallie Grade Level: 7 ID #: 1 printing highschoolstudent: Smith, Bert Grade Level: 11 ID #: 2 GPA: 3.67 printing school: Faculty: Lovelace, Ada Subject: Mathematics Einstein, Albert Subject: Physics Hopper, Grace Subject: Computer Science Turing, Alan Subject: Mathematics Curie, Marie Subject: Chemistry Madison, Dolly Subject: Government Angelou, Maya Subject: English Composition Student Body: Finch, Jem Grade Level: 11 ID #: 3 GPA: 3.4 Finch, Scout Grade Level: 4 ID #: 4 Adams, Natalie Grade Level: 11 ID #: 5 GPA: 2.4 Radley, Boo Grade Level: 12 ID #: 6 GPA: 1.7 Finch, Atticus Grade Level: 12 ID #: 7 GPA: 4.8 Benes, Elaine Grade Level: 9 ID #: 8 Henry, Patrick Grade Level: 11 ID #: 9 just seniors: Radley, Boo Grade Level: 12 ID #: 6 GPA: 1.7 Finch, Atticus Grade Level: 12 ID #: 7 GPA: 4.8
1. Submit your Person class here.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
