Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to update my java package (EmployeePackage) to not use import java.util.Date; but rather the include Date.java (which does compile just fine). I think

I need to update my java package (EmployeePackage) to not use import java.util.Date; but rather the include Date.java (which does compile just fine). I think I need to update Test.java. Here are all the packages, though please help.

Also, here is the assignment. We are not allowed to use import java.util.Date; but unfortunately that's the only way I have gotten it to work so far. 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.

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());

}

}

Thank you so much in advance. Stuck on this.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How did the authors address the fallacy of homogeneity?

Answered: 1 week ago

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

Describe the major barriers to the use of positive reinforcement.

Answered: 1 week ago