In: Computer Science
Using Java, write the the following code. Only the bold needs to be answered
Here is the driver:
package assign
public class A3Driver {
public static void main(String[] args) {
//Test GSUStudent object
GSUStudentWorker gsw = new GSUStudentWorker("Bunny","Bugs", 2000, 9, 8, 9001234);
gsw.setGPA(3.7);
gsw.setHourlyRate(10.00);
gsw.setTotalHours(30);
System.out.println(gsw);
GSUStudentWorker gsw2 = new GSUStudentWorker("Bunny","Betty", 1999, 9, 8, 9002413);
gsw2.setGPA(4.0);
gsw2.setHourlyRate(10.00);
gsw2.setTotalHours(45);
System.out.println(gsw2);
//Test GSUStoreSupervisor
GSUStoreSupervisor gss = new GSUStoreSupervisor("Duck","Daffy", 1980, 9, 8);
gss.setMonthlyPay(4000);
System.out.println(gss);
//test GSUSuperStudent
GSUSuperStudent gsuper = new GSUSuperStudent("Mouse","Minny", 1990, 9, 8, 9004321);
gsuper.setGPA(3.9);
gsuper.setHourlyRate(10.00);
gsuper.setTotalHours(30);
gsuper.setMonthlyPay(4000);
System.out.println(gsuper);
}
}
1. The Person class
a. Person is an abstract class.
b. All class variables of the Person class must be private.
c.is a class with a single constructor, Person(String lName, String fName, int birthYear, int birthMonth, int birthDay). All arguments of the constructor should be stored as class variables. There should only be getter methods for first and last name variables. There should be no getters or setters forbirthYear, birthMonth, birthDay.
The method computeAge() takes no arguments and returns the person’s computed age (as of today's date) as a string of the form "X years, Y months and Z days". Hint: Use the LocalDate and Period classes.
i. e.g. "21 years, 2 months and 3 days". ii. e.g. "21 years and 3 days".
iii. e.g. "21 years and 2 months". iv. e.g. "21 years".
v. e.g. "2 months and 3 days".
The toString method returns a string comprised of the results of
getFname, getLName and computeAge. E.g.
i. “Bunny Bugs is 19 years and 1 day old”
The equals method returns true if the name and date of birth of this person and the other person are the same, otherwise return false.
2. The Employee interface
a.has a single method, getPay(), which returns a
double
representing the pay earned for the period in dollars and cents.
3. The MonthlyEmployee interface
a. This interface extends the Employee interface.
b. has a single void method, setMonthlyPay(double perMonth),
which
takes a double as an argument. The argument is the amount earned for the month in dollars and cents.
4. The HourlyEmployee interface
a. This interface extends the Employee interface.
b. has a void method, setHourlyRate(double perHour), which takes
a
double as an argument. The argument is the amount earned for
each hour that the employee works.
c. has a void method, setTotalHours(double hoursWorked),
which
takes a double as an argument. The argument is the total hours worked for the week.
Has a final integer variable MAX_WEEKLY_HOURS, which is assigned
a value of 40. This variable is used to assess if the total
hours worked exceeds the mandated hours.
Has a final double variable OVERTIME_RATE, which is assigned a
value of 1.75. This variable is used to compute the pay amount for hours worked that exceeds the mandated hours.
5. The Student class
a. The Student class is abstract.
The Student class extends the Person class.
All (if any) class variables of the Student class must be private.
has an abstract void method, setGPA(double gpa), which takes a double as an argument. The argument is the grade point average of the student using a 4.0 scale.
has an abstract method, getGPA(), which returns a double. The returned value is the grade point average of the student using a 4.0 scale.
6. The GSUStudentWorker class
a. The GSUStudentWorker class extends the Student class and
inherits from the HourlyEmployee interface.
is a class with a single constructor, GSUStudentWorker (String lName, String fName, int birthYear, int birthMonth, int birthday, int eid). There should be a getter and setter for eid, which is the Eagle ID of the student.
All class variables of the Student class must be private.
has a void method, setGPA(double gpa), which takes a double as an argument. The argument is the grade point average of the student using a 4.0 scale.
has a method, getGPA(), which returns a double. The returned value is the grade point average of the student using a 4.0 scale.
f. Has a toString() method that returns a string in the form shown below.
i. Bugs Bunny is 19 years and 15 days old and is a Great Sauce student with a 3.7 GPA who earned $300.00 this week.
7. The GSUStoreSupervisor class
a. The GSUStoreSupervisor class extends the Person class and
inherits from the MonthlyEmployee interface.
is a class with a single constructor, GSUStoreSupervisor(String lName, String fName, int birthYear, int birthMonth, int birthDay).
All class variables of the Student class must be private.
Has a toString() method that returns a string in the form shown below.
i. Daffy Duck is 39 years and 15 days old and is a Great Sauce monthly employee who earned $4000.00 this period.
8. The GSUSuperStudent class
a. GSUSuperStudent has found a way to get paid as a monthly
employee and as a student employee.
The GSUSuperStudent class extends the GSUStudentWorker class and inherits from the MonthlyEmployee interface.
All class variables of the Student class must be private.
Has a toString() method that returns a string in the form shown below.
i. Minny Mouse is 29 years and 15 days old and is a Great Sauce student with a 3.9 GPA who earned $4300.00 this period.
Example output:
__________Example from A3Driver shown below
Bugs Bunny is 19 years and 15 days old and is a Great Sauce student with a 3.7 GPA who earned $300.00 this week.
Betty Bunny is 20 years and 15 days old and is a Great Sauce student with a 4.0 GPA who earned $487.50 this week.
Daffy Duck is 39 years and 15 days old and is a Great Sauce monthly employee who earned $4000.00 this period.
Minny Mouse is 29 years and 15 days old and is a Great Sauce student with a 3.9 GPA who earned $4300.00 this period.
Source Code in Java:
interface Employee
{
public double getPay();
}
class MonthlyEmployee implements Employee
{
private double perMonth; //instance variable to store pay per
month
public void setMonthlyPay(double perMonth) //method to set pay per
month
{
this.perMonth=perMonth;
}
public double getPay() //method to get pay for the Employee
{
return perMonth;
}
}
class HourlyEmployee implements Employee
{
//final variables to store constants
private final int MAX_WEEKLY_HOURS=40;
private final double OVERTIME_RATE=1.75;
private double perHour,hoursWorked; //instance variable
public void setHourlyRate(double perHour) //method to set pay her
hour
{
this.perHour=perHour;
}
public void setTotalHours(double hoursWorked) //method to set hours
worked
{
this.hoursWorked=hoursWorked;
}
public double getPay() //method to get pay for the Employee
{
if(hoursWorked<=MAX_WEEKLY_HOURS)
return perHour*hoursWorked;
else
return
perHour*MAX_WEEKLY_HOURS+perHour*(hoursWorked-MAX_WEEKLY_HOURS)*OVERTIME_RATE;
}
}