Question

In: Computer Science

For this assignment, you will create a hierarchy of five classes to describe various elements of...

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:

firstName lastName

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:

Mary Smith
   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:

Sarah Lee
   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:

Rebecca Dovi
   Subject: Computer Science
Note: there are three spaces before "Subject: ...".

School

Variables:

ArrayList<Student> students - A list of students at the school.

ArrayList<Teacher> teachers - A list of teachers at the school.

Methods:

School(ArrayList<Student> students, ArrayList<Teacher> teachers) - A constructor that specifies teachers and students at a school.

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:

John Doe


printing student:

Sallie Smithers
   Grade Level: 7
   ID: 1


printing highschoolstudent:

Bert Smith
   Grade Level: 11
   ID: 2
   GPA: 3.67


printing school:

Faculty:
Ada Lovelace
   Subject: Mathematics
Albert Einstein
   Subject: Physics
Grace Hopper
   Subject: Computer Science
Alan Turing
   Subject: Mathematics
Marie Curie
   Subject: Chemistry
Dolly Madison
   Subject: Government
Maya Angelou
   Subject: English Composition


Student Body:
Jem Finch
   Grade Level: 11
   ID: 3
   GPA: 3.4
Scout Finch
   Grade Level: 4
   ID: 4
Natalie Adams
   Grade Level: 11
   ID: 5
   GPA: 2.4
Boo Radley
   Grade Level: 12
   ID: 6
   GPA: 1.7
Atticus Finch
   Grade Level: 12
   ID: 7
   GPA: 4.8
Elaine Benes
   Grade Level: 9
   ID: 8
Patrick Henry
   Grade Level: 11
   ID: 9



just seniors:
Boo Radley
   Grade Level: 12
   ID: 6
   GPA: 1.7
Atticus Finch
   Grade Level: 12
   ID: 7
   GPA: 4.8

1. Submit your Person class here.

NOTE: You MUST use the class name "Person" for this submission.

Solutions

Expert Solution

student_runner_school.java


import java.io.IOException;
import java.util.ArrayList;

public class student_runner_School
{

public static void main(String arg[]) throws IOException
{
Person p = new Person("John", "Doe");
System.out.println("printing person:\n");
System.out.println(p);

Student s = new Student("Sallie", "Smithers", 7);
System.out.println("\n\nprinting student:\n");
System.out.println(s);

System.out.println("\n\nprinting highschoolstudent:\n");
HighSchoolStudent h = new HighSchoolStudent("Bert", "Smith", 11, 3.67);
System.out.println(h);

ArrayList<Student> stu = new ArrayList<Student>();
stu.add(new HighSchoolStudent("Jem", "Finch", 11, 3.4));
stu.add(new Student("Scout", "Finch", 4));
stu.add(new HighSchoolStudent("Natalie", "Adams", 11, 2.4));
stu.add(new HighSchoolStudent("Boo", "Radley", 12, 1.7));
stu.add(new HighSchoolStudent("Atticus", "Finch", 12, 4.8));
stu.add(new Student("Elaine", "Benes", 9));
stu.add(new Student("Patrick", "Henry", 11));

ArrayList<Teacher> tea = new ArrayList<Teacher>();
tea.add(new Teacher("Ada", "Lovelace", "Mathematics"));
tea.add(new Teacher("Albert", "Einstein", "Physics"));                 
tea.add(new Teacher("Grace", "Hopper", "Computer Science"));
tea.add(new Teacher("Alan", "Turing", "Mathematics"));
tea.add(new Teacher("Marie", "Curie", "Chemistry"));
tea.add(new Teacher("Dolly", "Madison", "Government"));
tea.add(new Teacher("Maya", "Angelou", "English Composition"));

School sch = new School(stu, tea);
System.out.println("\n\nprinting school: \n");
System.out.println(sch);

System.out.println("\n\njust seniors: \n" + sch.getGradeLevel(12));

}
}

Person.java


public class Person {

   private String firstName;
   private String lastName;
  
   //Constructor that takes in String parameters representing the first and last names
   public Person(String fName, String lName)
   {
       firstName = fName;
       lastName = lName;
   }
  
   //Returns a string in the following format:
   //lastName, firstName
   public String toString()
   {
       return (lastName + ", " + firstName);
   }
}

HighSchoolStudent.java


public class HighSchoolStudent extends Student{

   private 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.
   public HighSchoolStudent(String fName, String lName, int gLevel, double inputGpa)
   {
       super(fName, lName, gLevel);
       if(inputGpa >= 0 && inputGpa <= 5)
           gpa = inputGpa;
       else
           gpa = 0;
      
   }
  
   // 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: ...".
   public String toString()
   {
       String whole = super.toString();
       whole = whole + "\n   " + "GPA: " + gpa;
       return whole;
   }
  
  
}

Teacher.java


public class Teacher extends Person{
  
   // A String representing the academic subject taught by the teacher.
   private String subject;
  
   // The first and last names should be set by calling the constructor of the parent class.
   public Teacher(String fName, String lName, String subject1)
   {
       super(fName, lName);
       subject = subject1;
   }
  
   // Returns a two line String with Teacher info formatted as follows:
   // Dovi, Rebecca
   //    Subject: Computer Science
   // Note: there are three spaces before "Subject: ...".
   public String toString()
   {
       String whole = super.toString();
       whole = whole + "\n   " + "Subject: " + subject;
       return whole;
   }
  

}

School.java

import java.util.ArrayList;

public class School {

   // A list of students at the school.
   private ArrayList<Student> students;
   // A list of teachers at the school.
   private ArrayList<Teacher> teachers;
  
   // A constructor that specifies teachers and students at a school.
   public School(ArrayList<Student> students1, ArrayList<Teacher> teachers1)
   {
       students = students1;
       teachers = teachers1;
   }
  
   // 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.
   public String getGradeLevel(int level)
   {
       String whole = "";
       for(Student student1: students)
       {
           if(student1.getLevel() == level)
               whole = whole + student1 + "\n";
       }
       return whole;
   }
  
   // Returns a multi-line 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}
   public String toString()
   {
       String wholeString = "";
      
       String wholeStudents = "";
       for(Student student1: students)
       {
           wholeStudents = wholeStudents + student1 + "\n";
       }
      
       String wholeTeachers = "";
       for(Teacher teacher1: teachers)
       {
           wholeTeachers = wholeTeachers + teacher1 + "\n";
       }
       wholeString = "Faculty:" + "\n" + wholeTeachers + "\n\n";
       wholeString = wholeString + "Student Body:" + "\n" + wholeStudents;
       return wholeString;
   }
  
  
  
  
}

Student.java


public class Student extends Person{
  
   private static int studentId = 1;
   private int level;
   private int id;
  
   // 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.
   public Student(String fName, String lName, int gLevel)
   {
       super(fName, lName);
       if(gLevel >= 0 && gLevel <= 12)
           level = gLevel;
       else
           level = 0;
       id = studentId;
       studentId++;
   }
  
   // Returns the student's grade level.
   public int getLevel()
   {
       return level;
   }

   // 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 #: ...".
   public String toString()
   {
       String whole = super.toString();
       whole = whole + "\n   " + "Grade Level: " + level;
       whole = whole + "\n   " + "ID #: " + id;
       return whole;
   }
  
  
  
  
}



Related Solutions

For this assignment you will create a set of simple classes that model a cookbook. The...
For this assignment you will create a set of simple classes that model a cookbook. The cookbook will consist of set or recipes. Each recipe will consist of a set of ingredients and instructions. Your submission will consist of the below three classes and a test driver (the only class with a main()) that exercises the functionality of your system. You will need to implement the following classes based on the description of their attributes and operations: Ingredient name -...
C++ Programming. Create a class hierarchy to be used in a university setting. The classes are...
C++ Programming. Create a class hierarchy to be used in a university setting. The classes are as follows: The base class isPerson. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The classshould also have a static data member called nextID which is used to assignanID numbertoeach object created(personID). All data members must be private. Create the following member functions: Accessor functions to allow access to first name and last name (updates and retrieval). These functions should...
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
In this assignment, students should create five Java classes called Point, Circle, Square, Rectangle, and TestAll,...
In this assignment, students should create five Java classes called Point, Circle, Square, Rectangle, and TestAll, as well as a Java interface called FigureGeometry. The TestAll class should implement the main method which tests all of the other files created in the assignment. After the assignment has been completed, all six files should be submitted for grading into the Dropbox for Assignment 3, which can be found in the Dropbox menu on the course website. Students should note that only...
Describe the various elements of a control system.
Describe the various elements of a control system.
Describe the classes of repetitive elements that are present in the human genome?
Describe the classes of repetitive elements that are present in the human genome?
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that...
Using JAVA: This assignment is about aggregation and class collaboration. You will create several Classes that will be part of an overall class named InstrumentDisplay. The classes are FuelGage, Odometer, MilesSinceLastGas, and CruisingRange. The FuelGage should assume a 15 gallon tank of gasoline and an average consumption of 1 gallon every 28 miles. It should increment in 1 gallon steps when you "add gas to the tank". It should decrement by 1 every 28 miles. It should display its current...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape,...
Java Solution Create a class hierarchy that represents shapes. It should have the following classes: Shape, Two Dimensional Shape, Three Dimensional Shape, Square, Circle, Cube, Rectangular Prism, and Sphere. Cube should inherit from Rectangular Prism. The two dimensional shapes should include methods to calculate Area. The three dimensional shapes should include methods to calculate surface area and volume. Use as little methods as possible (total, across all classes) to accomplish this, think about what logic should be written at which...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee Hierarchy that you created in Java in Programming Assignment 2 by adding an interface called Compensation with the following two methods: earnings() - receives no parameters and returns a double. raise(double percent) - receives one parameter which is the percentage of the raise and returns a void. Create the abstract class CompensationModel which implements the Compensation interface. Create the following classes as subclasses of...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee...
Assignment 3 - Enhanced Employee Hierarchy For this assignment, you are going to enhance the Employee Hierarchy that you created in Programming Assignment 2 by adding an interface called Compensation with the following two methods: earnings() - receives no parameters and returns a double. raise(double percent) - receives one parameter which is the percentage of the raise and returns a void. Create the abstract class CompensationModel which implements the Compensation interface. Create the following classes as subclasses of CompensationModel: SalariedCompensationModel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT