- 1

Please I need help with this exercise in Java.

1. Create a class, Person, with an instance variable, name. write appropriate getters and setters for the class. Also write a toString method for the class. 2. Employee that extends Person and has two additional Inst var, id & payRate, & an additional method, pay, that returns the Pay Rate, override the toString method accordingly. 3. Faculty, that extends Employee, & has 2 additional variables; officeHours of type String & teachingCourses, which is an array of courses. Each course has a course code & course title. Write appropriate getters, setters and toString methods for the class. 4. TestPersons, that has two methods; void printPerson (Person p) that prints it's argument. And a main method that creates an instance of each of the above classes and prints it using printPerson method.

14th Aug 2018, 11:23 AM
Muhammad Suleiman
Muhammad Suleiman - avatar
2 odpowiedzi
0
Cool. Got code?
14th Aug 2018, 11:49 AM
Janning⭐
Janning⭐ - avatar
0
import java.util.ArrayList; public class Person { String name; public Person(String name){ this.name = name; } public String getName(){ return name; } public void setName(String newName){ name = newName; } //What is the reason for making toString here?? toString for the name? } public class Employee extends Person{ int id; int payRate; public Employee(String name,int id, int payRate) { super(name); this.id = id; this.payRate = payRate; } public int pay(){ return payRate; } //I am not sure what is used for the toString, so I will just not do it;;; } public class Faculty extends Employee{ String officeHours; ArrayList<courses> teachingCourses = new ArrayList<courses>(); public Faculty(String name, int id, int payRate) { super(name, id, payRate); } public String getOfficeHours(){ return officeHours; } public void setOfficehours(String hour){ officeHours = hour; } } public class courses{ int code; String title; public courses(){ } } giving up in the middle of number 3... There are too much to do;
14th Aug 2018, 10:09 PM
Jang Jaeung
Jang Jaeung - avatar