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.
/*********************************Employee.java*******************/
package employee3;
public interface Employee {
public double getPay();
}
/************************MonthlyEmployee.java************************/
package employee3;
public interface MonthlyEmployee extends Employee {
public void setMonthlyPay(double perMonth);
}
/***********************************HourlyEmployee.java*********************/
package employee3;
/**
* The Interface HourlyEmployee.
*/
public interface HourlyEmployee extends Employee {
/**
* Sets the hourly rate.
*
* @param perHour the new hourly rate
*/
public void setHourlyRate(double perHour);
/**
* Sets the total hours.
*
* @param hoursWorked the new total hours
*/
public void setTotalHours(double hoursWorked);
/** The max weekly hours. */
final int MAX_WEEKLY_HOURS = 40;
/** The overtime rate. */
final double OVERTIME_RATE = 1.75;
}
/*************************************Student.java******************/
package employee3;
/**
* The Class Student.
*/
public abstract class Student extends Person {
/** The major. */
private String major;
/**
* Instantiates a new student.
*
* @param id the id
* @param name the name
* @param major the major
*/
public Student(String id, String name, String major)
{
super(id, name);
this.major = major;
}
/**
* Gets the major.
*
* @return the major
*/
public String getMajor() {
return major;
}
/**
* Sets the major.
*
* @param major the new major
*/
public void setMajor(String major) {
this.major = major;
}
/**
* Sets the gpa.
*
* @param gpa the new gpa
*/
public abstract void setGPA(double gpa);
/**
* Gets the gpa.
*
* @return the gpa
*/
public abstract double getGPA();
}
/*********************************Person.java*******************/
package employee3;
/**
* The Class Person.
*/
public class Person {
/** The id. */
private String id;
/** The name. */
private String name;
/**
* Instantiates a new person.
*
* @param id the id
* @param name the name
*/
public Person(String id, String name) {
super();
this.id = id;
this.name = name;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return id + ", " + name;
}
}
Please let me know if you have any doubt or modify the answer,
Thanks :)