Below instruction are part of my HW. and i'm stuck on this. I need to have new class created as mentioned below and out printed on console.
Output needs to look like in attached file.
Attachment 10100
Create a Test class (in different file)to test the following functionality in its
main method.
a. Declare a variable named currentEmployee of type Employee.
b. Create an Employee object with name Alice and the weekly wage rate 1000 and assign it to the above variable.
c. Print to the console the string representation of this object.
d. Using any of the loop constructs, iterate over the computePayStub of this object with the hours 10, 20, 30, 40, 50, and 60. Display the wages as shown in the sample below.
e. Create a Consultant object with name Bob and the hourly wage rate 100. Reassign the currentEmployee to this object.
f. Repeat the steps shown in c) and d) for this object.
In below file where i have created classes and implement the specified functionality.
package hw3.part2;
import javax.swing.JOptionPane;
import java.text.NumberFormat;
public class Employee {
//instance variables
private String name;
private int wageRate;
NumberFormat moneyFormatter=NumberFormat.getCurrencyInstance();
public Employee(){}
//single constructor
public Employee(String theName, int theWageRate){
name=theName;
wageRate=theWageRate;
}
public String getName() {
return name;
}
public void setName(String newName) {
this.name = newName;
}
public int getWageRate() {
return wageRate;
}
public void setWageRate(int newWageRate) {
this.wageRate = newWageRate;
}
//compute computePayStub
public double computePayStub(double hours)
{
double perHourRate=wageRate/40;
double weekleyWadge=0.0;
if (hours>=40){
weekleyWadge=(perHourRate*40);
}
else if (hours<40){
weekleyWadge=(perHourRate*hours);
}
return weekleyWadge;
}
public String toString (){
return "Employee: Alice";
}
}
//Create a derived class from the Employee class named Consultant
class consultant extends Employee{
public consultant()
{
}
public consultant(String theName,int theWageRate){
super (theName, theWageRate);
}
//Override computePayStub method
public double computePayStub(double hours){
double hourlyRate=getWageRate()/40;
double weekleyWadge=0.0;
if (hours>=40){
if (hours <=50){
weekleyWadge=((hourlyRate*hours)*1.5);
} else {
weekleyWadge=((hourlyRate*50)*1.5); }
}
else {
weekleyWadge=(hourlyRate*hours);}
return weekleyWadge; }
public String toString (){
return "Consultant: Bob";
}
}