Employee employee = new Employee(theName, hoursWorked, hourlyPayRate);
System.out.printf( "Employee Name: %s, Weekly pay is $%d%n",
employee.name, employee.getWeeklyPay() );
}
}
}
class Employee {
String name;
int hours;
int hourlyPayRate;
int weeklyPay;
public Employee(String name, int hours, int rate) {
this.name = name;
this.hours = hours;
hourlyPayRate = rate;
computeWeeklyPay();
}
private void computeWeeklyPay() {
weeklyPay = hours * hourlyPayRate;
}
public int getWeeklyPay() {
return weeklyPay;
}
}
This is the part I am unsure about. I have created the class but when I try and implement the constructor in my above code it will not work. The error is about variables but the variables I have used are declared in my code which again makes no sense to me.