Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have an inheritance project that I need help with. They gave me 2 code blocks

ID: 3625257 • Letter: I

Question

I have an inheritance project that I need help with. They gave me 2 code blocks and want me to edit them as the questions asks.

Redo the class Employee and the class HourlyEmployee in Displays 7.2 and 7.3 so that the class Date is an inner class of the class Employee and an inherited inner class of the class HourlyEmployee.

Thanks, any help is appreciated.

Display 7.2:

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



public class Employee
{
private String name;
private Date hireDate;

public Employee( )
{
name = "No name";
hireDate = new Date("Jan", 1, 1000); //Just a placeholder.
}


public Employee(String theName, Date theDate)
{
if (theName == null || theDate == null)
{
System.out.println("Fatal Error creating employee.");
System.exit(0);
}
name = theName;
hireDate = new Date(theDate);
}

public Employee(Employee originalObject)
{
name = originalObject.name;
hireDate = new Date(originalObject.hireDate);
}

public String getName( )
{
return name;
}

public Date getHireDate( )
{
return new Date(hireDate);
}


public void setName(String newName)
{
if (newName == null)
{
System.out.println("Fatal Error setting employee name.");
System.exit(0);
}
else
name = newName;
}


public void setHireDate(Date newDate)
{
if (newDate == null)
{
System.out.println("Fatal Error setting employee hire date.");
System.exit(0);
}
else
hireDate = new Date(newDate);
}


public String toString( )
{
return (name + " " + hireDate.toString( ));
}


public boolean equals(Employee otherEmployee)
{
return (name.equals(otherEmployee.name)
&& hireDate.equals(otherEmployee.hireDate));
}
}

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

Display 7.3:



public class HourlyEmployee extends Employee
{
private double wageRate;
private double hours; //for the month

public HourlyEmployee( )
{
super( );
wageRate = 0;
hours = 0;
}


public HourlyEmployee(String theName, Date theDate,
double theWageRate, double theHours)
{
super(theName, theDate);
if ((theWageRate >= 0) && (theHours >= 0))
{
wageRate = theWageRate;
hours = theHours;
}
else
{
System.out.println(
"Fatal Error: creating an illegal hourly employee.");
System.exit(0);
}
}

public HourlyEmployee(HourlyEmployee originalObject)
{
super(originalObject);
wageRate = originalObject.wageRate;
hours = originalObject.hours;
}

public double getRate( )
{
return wageRate;
}

public double getHours( )
{
return hours;
}


public double getPay( )
{
return wageRate*hours;
}


public void setHours(double hoursWorked)
{
if (hoursWorked >= 0)
hours = hoursWorked;
else
{
System.out.println("Fatal Error: Negative hours worked.");
System.exit(0);
}
}


public void setRate(double newWageRate)
{
if (newWageRate >= 0)
wageRate = newWageRate;
else
{
System.out.println("Fatal Error: Negative wage rate.");
System.exit(0);
}
}

public String toString( )
{
return (getName( ) + " " + getHireDate( ).toString( )
+ " $" + wageRate + " per hour for " + hours + " hours");
}

public boolean equals(HourlyEmployee other)
{
return (getName( ).equals(other.getName( ))
&& getHireDate( ).equals(other.getHireDate( ))
&& wageRate == other.wageRate
&& hours == other.hours);
}
}

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

Explanation / Answer

//Only needed to change Employee class because HourlyEmployee extends Employee it will inherit the inner class of Date when i added it to Employee. You make a inner class by simply putting another class within another class like i did at the end of this code. I added getters and setters for the Date class but you might want to add some more functions or change what the constructors do public class Employee { private String name; private Date hireDate; public Employee( ) { name = "No name"; hireDate = new Date("Jan", 1, 1000); //Just a placeholder. } public Employee(String theName, Date theDate) { if (theName == null || theDate == null) { System.out.println("Fatal Error creating employee."); System.exit(0); } name = theName; hireDate = new Date(theDate); } public Employee(Employee originalObject) { name = originalObject.name; hireDate = new Date(originalObject.hireDate); } public String getName( ) { return name; } public Date getHireDate( ) { return new Date(hireDate); } public void setName(String newName) { if (newName == null) { System.out.println("Fatal Error setting employee name."); System.exit(0); } else name = newName; } public void setHireDate(Date newDate) { if (newDate == null) { System.out.println("Fatal Error setting employee hire date."); System.exit(0); } else hireDate = new Date(newDate); } public String toString( ) { return (name + " " + hireDate.toString( )); } public boolean equals(Employee otherEmployee) { return (name.equals(otherEmployee.name) && hireDate.equals(otherEmployee.hireDate)); } public class Date{ private String month="January"; private int day=01; private int year=2012; public Date(String month, int day, int year) { this.month=month; this.day=day; this.year=year; } public Date(Date newDate) { this.month=newDate.getMonth(); this.day=newDate.getDay(); this.year=newDate.getYear(); } public String getMonth() { return month; } public void setMonth(String month) { this.month = month; } public int getDay() { return day; } public void setDay(int day) { this.day = day; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote