Question
Main topics: Composition - Aggregation Inheritance Exercise This week we will be practicing writing an extended class, and a driver class for a numerous class
Main topics:
Composition - Aggregation
Inheritance
Exercise
This week we will be practicing writing an extended class, and a driver class for a numerous class project.
Getting Started
To start this exercise, you should:
1. Open eclipse and start a new Java project named Lab06
2. Add a Class (named Person) to this project, and copy the contents of the Person.java file provided into it.
3. Add a Class (named Student) to this project, and copy the contents of the Student.java file provided into it.
4. Add a Class (named Principle) to this project, the contents of which you will be writting from scratch.
5. Add a Class (named School) to this project, and copy the contents of the School.java file provided into it.
6. Add a Class (named SchoolDriver) to this project, the contents of which you will be writting from scratch.
Requirements
Person.java
A very simple class which models some of the functionality of a person. This class is complete and must not be modified.
Student.java
A very simple class which extends the Person class to also model some of the functionality of a student. This class is complete and must not be modified.
Principle.java
A very simple class which extends the Person class to also model some of the functionality of a principle. The extra data member this time is a salary. This class you must write, such that:
1. You write the standard default and specifying constructors, which utilize the base Person classes default and specifying constructors respectively.
2. You write the standard accessor and mutator.
3. You override Persons toString method.
School.java
A very simple class which models some of the functionality of a school. Pay close attention as to how the sole principle and the various students are incorporated - which is composition? - which is aggregation? This class is complete and must not be modified.
SchoolDriver.java
A simple driver class to test all of the above classes. This class you must write, such that:
1. You construct two different schools.
2. You construct and add a different student to each school.
3. You construct one additional student, and add them to both schools.
4. You produce output that is at least functionally equivalent to the following:
Schools Name: Somewhere East
Principles Name: John Hawlks - $35000.0 Yearly
Jimmy - GPA - 3.5
Jenny - GPA - 3.8
Schools Name: Somewhere West
Principles Name: Amy Hope - $48000.0 Yearly
Jenny - GPA - 3.8
Billy - GPA - 3.8
____________________________________________
Person class
package Inheritance;
public class Person { private String name; public Person() { this(""); }
public Person(String name) { this.name = name; } public String getName() { return this.name; } public String toString() { return getName(); } }
___________________________________________
School class
import java.util.ArrayList;
public class School { private String name; private Principle principle; private ArrayList
__________________________________________
Student class
package Inheritance;
public class Student extends Person { private double gpa; public Student() { super(); this.gpa = 4.0; }
public Student(String name, double gpa) { super(name); this.gpa = gpa; } public double getGpa() { return this.gpa; } public String toString() { return super.toString() + " : " + this.getGpa(); } }
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