Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Person.java A very simple class which models some of the functionality of a pers

ID: 3600318 • Letter: P

Question

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:

You write the standard default and specifying constructors, which utilize the base Person classes’ default and specifying constructors respectively.

You write the standard accessor and mutator.

You override Person’s 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:

You construct two different schools.

You construct and add a different student to each school.

You construct one additional student, and add them to both schools.

You produce output that is at least functionally equivalent to the following:

School’s Name: Somewhere East

Principle’s Name: John Hawlks - $35000.0 Yearly Jimmy - GPA - 3.5

Jenny - GPA - 3.8

School’s Name: Somewhere West

Principle’s Name: Amy Hope - $48000.0 Yearly Jenny - GPA - 3.8

Billy - GPA - 3.8


Person:

public class Person
{
private String name;
  
public Person()
{
this("");
}
  
public Person(String name)
{
this.setName(name);
}
  
private void setName(String name)
{
this.name = name;
}
  
public String getName()
{
return this.name;
}
  
public String toString()
{
return this.getName();
}
}



School:

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(" Principle's Name: " + this.principle.toString());
for ( Student student : students )
System.out.println(" " + student.toString());
}
}


Student:


public class Student extends Person
{
private double gpa;
  
public Student()
{
super();
this.setGPA(0);
}

public Student(String name, double gpa)
{
super(name);
this.setGPA(gpa);
}
  
private void setGPA(double gpa)
{
this.gpa = gpa;
}
  
public double getGPA()
{
return this.gpa;
}
  
public String toString()
{
return super.toString() + " - GPA - " + this.getGPA();
}
}

Explanation / Answer

import java.util.*;

class Person

{

private String name;

  

public Person()

{

this("");

}

  

public Person(String name)

{

this.setName(name);

}

  

private void setName(String name)

{

this.name = name;

}

  

public String getName()

{

return this.name;

}

  

public String toString()

{

return this.getName();

}

}

class Principle extends Person

{

private double salary;

  

  

public Principle(String name,double salary)

{

super(name);

this.setSalary(salary);

}

  

private void setSalary(double salary)

{

this.salary = salary;

}

  

public double getSalary()

{

return this.salary;

}

  

public String toString()

{

super.toString();

return " Principle’s Name: "+super.toString()+"-$"+getSalary()+ " Yearly";

}

}

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(" Principle's Name: " + this.principle.toString());

for (int i = 0; i < students.size(); i++)

System.out.println(" " + students.get(i).toString());

}

}

class Student extends Person

{

private double gpa;

  

public Student()

{

super();

this.setGPA(0);

}

public Student(String name, double gpa)

{

super(name);

this.setGPA(gpa);

}

  

private void setGPA(double gpa)

{

this.gpa = gpa;

}

  

public double getGPA()

{

return this.gpa;

}

  

public String toString()

{

return super.toString() + " - GPA - " + this.getGPA();

}

}

class SchoolDriver

{

public static void main (String[] args)

{

School sch1 = new School("Somewhere East","John Hawlks",35000.0);

Student st1 = new Student("Jimmy",3.5);

sch1.addStudent(st1);

Student st2 = new Student("Jenny",3.8);

sch1.addStudent(st2);

sch1.schoolAudit();

School sch2 = new School("Somewhere West","Amy Hope",48000.0);

Student st3 = new Student("Jenny",3.8);

sch2.addStudent(st3);

Student st4 = new Student("Billy",3.8);

sch2.addStudent(st4);

sch2.schoolAudit();

}

}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote