Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to update my java package (EmployeePackage) to not use the date in Test.java below is an 3-item array not just manually entered. Also

I need to update my java package (EmployeePackage) to not use the date in Test.java below is an 3-item array not just manually entered. Also the corresponding method to collate and print in Employee.java.

Also, here is the assignment. This assignment will use the Employee, Name, Address, and Date classes which you developed for Module Assignment 6. You are to incorporate any fixes indicated in your Module 6 Assignment feedback for this assignment. Design two sub-classes of Employee, SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate for all hours over 40.

Create a 3-element Employee array and place the three Employees in this array. The test program should display all attributes for the three employees extracted from the array.

Here is a sample of the Test.java that I need which I found on a forum:

public static void main(String args[]) { Employee[] employees = new Employee[3]; // Salaried employee employees[0] = new SalariedEmployee("Edward", "Ward", new Address("1110 Post Haven Dr.", "Apollo Beach", "FL", "33572"), new AssignmentDate(15, 2, 2004), employees, 45000.0); // Hourly Employee (under 40 hours) employees[1] = new HourlyEmployee("Thomas", "Moore", new Address("1111 Post Haven Dr.", "Apollo Beach", "FL", "33572"), new AssignmentDate(15,5, 2002), employees, 15.00, 39.5); // Hourly Employee (over 40 hours) employees[2] = new HourlyEmployee("John", "Smith", new Address("1113 Post Haven Dr.", "Apollo Beach", "FL", "33572"), new AssignmentDate(6, 3, 2012), employees, 20, 60);

// display all employees for (Employee e: employees) { System.out.println("------- START EMPLOYEE --------"); System.out.println(e.displayEmployeeInformation()); System.out.printf("%s ", e.getPay()); System.out.println("------- FINISH EMPLOYEE -------"); System.out.println(); } } }

Thank you in advance.

Employee.java

----------------------

import java.util.Date;//need to get rid of this.

public class Employee

{

private int empID;

private Address address;

private Name name;

private Date date;

public Employee()

{

}

public Employee(int empID)

{

this.empID = empID;

}

public int getEmpID()

{

return empID;

}

public void setEmpID(int empID)

{

this.empID = empID;

}

public Address getAddress()

{

return address;

}

public void setAddress(Address address)

{

this.address = address;

}

public Name getName()

{

return name;

}

public void setName(Name name)

{

this.name = name;

}

public Date getDate()

{

return date;

}

public void setDate(Date date)

{

this.date = date;

}

}

--------------------end Employee.java----------

Address.java

public class Address {

private String addr;

public Address(String addr) {

super();

this.addr = addr;

}

public String getAddr() {

return addr;

}

public void setAddr(String addr) {

this.addr = addr;

}

}

-------end Address.java-----------

Date. java

public class Date

{

private int month; // 1-12

private int day; // 1-31 based on month

private int year; // any year

Date()

{

}

// constructor: call checkMonth to confirm proper value for month;

// call checkDay to confirm proper value for day

public Date( int theMonth, int theDay, int theYear )

{

month = checkMonth( theMonth ); // validate month

year = theYear; // could validate year

day = checkDay( theDay ); // validate day

} // end Date constructor

// utility method to confirm proper month value

private int checkMonth( int testMonth )

{

if ( testMonth > 0 && testMonth <= 12 ) // validate month

return testMonth;

else // month is invalid

{

System.out.printf(

"Invalid month (%d) set to 1.", testMonth );

return 1; // maintain object in consistent state

} // end else

} // end method checkMonth

// utility method to confirm proper day value based on month and year

private int checkDay( int testDay )

{

int daysPerMonth[] =

{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

// check if day in range for month

if ( testDay > 0 && testDay <= daysPerMonth[ month ] )

return testDay;

// check for leap year

if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||

( year % 4 == 0 && year % 100 != 0 ) ) )

return testDay;

System.out.printf( "Invalid day (%d) set to 1.", testDay );

return 1; // maintain object in consistent state

} // end method checkDay

// return a String of the form month/day/year

public String toString()

{

return String.format( "%d/%d/%d", month, day, year );

} // end method toString

//The birthdate is to be displayed using a

//customized toDateString method in the Date class.

public void toDateString()

{

System.out.printf("%d/%d/%d", month, day, year);

}

}

--------End Date.java----------------

HourlyEmployee.java

public class HourlyEmployee extends Employee {

private double hourlyrate;

private double hours_worked;

private double earnings;

public HourlyEmployee(double hourlyrate, double hours_worked) {

super();

this.hourlyrate = hourlyrate;

this.hours_worked = hours_worked;

}

public double getEarnings()

{

if(hours_worked<=40)

{

earnings=hours_worked*hourlyrate;

}

else if(hours_worked>40)

{

earnings=40*hourlyrate+(hours_worked-40)*hourlyrate*1.5;

}

return earnings;

}

public double getHourlyrate() {

return hourlyrate;

}

public void setHourlyrate(double hourlyrate) {

this.hourlyrate = hourlyrate;

}

public double getHours_worked() {

return hours_worked;

}

public void setHours_worked(double hours_worked) {

this.hours_worked = hours_worked;

}

public void setEarnings(double earnings) {

this.earnings = earnings;

}

}

----------end HourlyEmployee.java----------

Name.java

public class Name {

private String name;

public Name(String name) {

super();

this.name = name;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

}

------end Name.java---------

SalariedEmployee.java

public class SalariedEmployee extends Employee {

private double annualSalary;

public SalariedEmployee(double annualSalary) {

super();

this.annualSalary = annualSalary;

}

public double getAnnualSalary() {

return annualSalary;

}

public void setAnnualSalary(double annualSalary) {

this.annualSalary = annualSalary;

}

}

-------End SalariedEmployee.java---------

Test.java (main)

import java.util.Date;

public class Test {

public static void main(String[] args) {

System.out.println("_____Salaried Employee_____");

SalariedEmployee se=new SalariedEmployee(50000);

se.setEmpID(1234);

se.setName(new Name("Williams"));

se.setAddress(new Address("4,Richmond Street"));

se.setDate(new Date("Oct-11-2014"));

System.out.println("Employee Id :"+se.getEmpID());

System.out.println("Employee Name :"+se.getName().getName());

System.out.println("Employee Address :"+se.getAddress().getAddr());

System.out.println("Joining Date :"+se.getDate());

System.out.println("The Annual Salary :"+se.getAnnualSalary());

System.out.println(" _____Hourly Employee_____");

HourlyEmployee he1=new HourlyEmployee(8.5,39);

he1.setEmpID(4567);

he1.setName(new Name("Kane"));

he1.setAddress(new Address("5,lake View Road"));

he1.setDate(new Date("Nov-12-2015"));

System.out.println("Employee Id :"+he1.getEmpID());

System.out.println("Employee Name :"+he1.getName().getName());

System.out.println("Employee Address :"+he1.getAddress().getAddr());

System.out.println("Joining Date :"+he1.getDate());

System.out.println("The Earnings Of An HourlyEmployee :"+he1.getEarnings());

System.out.println(" _____Hourly Employee_____");

HourlyEmployee he2=new HourlyEmployee(9.5,47);

he2.setEmpID(1111);

he2.setName(new Name("John"));

he2.setAddress(new Address("17,Villey Parley Street"));

he2.setDate(new Date("Dec-13-2011"));

System.out.println("Employee Id :"+he2.getEmpID());

System.out.println("Employee Name :"+he2.getName().getName());

System.out.println("Employee Address :"+he2.getAddress().getAddr());

System.out.println("Joining Date :"+he2.getDate());

System.out.println("The Earnings Of An HourlyEmployee :"+he2.getEarnings());

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions