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 students; public School() { this("", "", 0.0); } public School(String sName, String pName, double salary) { this.setName(sName); this.principle = new Principle(pName, salary); this.students = new ArrayList(); } private void setName(String name) { this.name = name; } public String getName() { return this.name; } public void addStudent(Student student) { this.students.add(student); } public void schoolAudit() { System.out.println("School\'s Name: " + this.getName()); System.out.println("\tPrinciple\'s Name: " + this.principle.toString()); for ( Student student : students ) System.out.println("\t\t" + student.toString()); } }

__________________________________________

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

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!