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

Assignment 5, CSE 205, 75 Points Due Date: Friday, October 6,2017, at 1159pm Imp

ID: 3587872 • Letter: A

Question

Assignment 5, CSE 205, 75 Points Due Date: Friday, October 6,2017, at 1159pm Important: This is an individual assigment. Please do not collaborate. Reading: Review lecture material and examples posted in the class website related to inheritance. Also, check the inheritance activity solutions posted. Assignment Description: During this homework, you will be implementing the following class hierarchy that implements university systems. In this university system, the university is associated with multiple people types People can be Employee type or Student type. Employee can be either Faculty or Staff. The following dass diagram show the relationship among objects. Universh) People ocaton String people People Saing Faculty

Explanation / Answer

import java.util.ArrayList; class People { private final String firstName; private final String lastName; private final String phoneNo; public double payRate; public double monthlyPay; People(String firstName, String lastName, String phoneNo) { this.firstName = firstName; this.lastName = lastName; this.phoneNo = phoneNo; this.payRate = 0; this.monthlyPay = 0; } @Override public String toString() { return getName() + " " + this.phoneNo; } public String getName() { return this.firstName + " " + this.lastName; } public void calculatePay() { this.monthlyPay = 0; } public double monthlyPay() { return this.monthlyPay; } } class Employee extends People { public final int payScale; Employee(String firstName, String lastName, String phoneNo, double payRate, int payScale) { super(firstName, lastName, phoneNo); this.payScale = payScale; } } class Faculty extends Employee { private final ArrayList classesTeach; Faculty(String firstName, String lastName, String phoneNo, double payRate, int payScale) { super(firstName, lastName, phoneNo, payRate, payScale); classesTeach = new ArrayList(); calculatePay(); } public void addClass(String className) { this.classesTeach.add(className); } @Override public String toString() { StringBuilder result = new StringBuilder(); result.append(getName()).append(" "); for (String className : classesTeach) { result.append(className).append(" "); } result.append(monthlyPay()).append(" "); return result.toString(); } @Override public void calculatePay() { this.monthlyPay = this.payRate / this.payScale + 500 * this.classesTeach.size(); } } class Staff extends Employee { private final String jobTitle; Staff(String firstName, String lastName, String phoneNo, double payRate, int payScale, String jobTitle) { super(firstName, lastName, phoneNo, payRate, payScale); this.jobTitle = jobTitle; } @Override public String toString() { calculatePay(); return getName() + " " + jobTitle + " " + monthlyPay(); } @Override public void calculatePay() { monthlyPay = payRate / payRate; } } class Student extends People { private double gpa; private String major; Student(String firstName, String lastName, String phoneNo, String major) { super(firstName, lastName, phoneNo); this.major = major; this.gpa = 0; } public void setGpa(double gpa) { this.gpa = gpa; } public void changeMajor(String major) { this.major = major; } @Override public String toString() { return super.toString() + " " + major + gpa; } } public class University { private final String name; private final String location; private final People peoples[]; public University(String name, String location, People[] people) { this.name = name; this.location = location; this.peoples = people; } @Override public String toString() { StringBuilder result = new StringBuilder("University:: " + "Name:: " + name + ' ' + "Location:: '" + location + ' '); for (People people : peoples) { result.append(people).append(" "); } return result.toString(); } public static void main(String[] args) { University university = new University("RGUKT", "NUZVID", getPeople()); System.out.println(university); } private static People[] getPeople() { People[] people = new People[3]; Student student = new Student("ram", "aleti", "34958235", "ECE"); student.setGpa(10); student.changeMajor("Cse"); people[0] = student; return people; } }