Hey all I was wondering if someone could help me out with a pretty simple Java program, I'm pretty sure most of the code I have is correct but at one point it is giving me an error of "cannot be resolved into variable". Can someone possibly take a look at my code?
Where it says grossPay in "WeeklyPayroll(name,hourlyWage,hours,grossPay);" is where I am getting my error.
Code:
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter an employee name for employee1: ");//Tom
String name = keyboard.nextLine();
System.out.print("Please enter weekly hours of working for employee1: ");//40
int hours = keyboard.nextInt();
System.out.print("Please enter hourly wage for employee1: ");//18
double hourlyWage = keyboard.nextDouble();
WeeklyPayroll employee1 = new WeeklyPayroll(name,hourlyWage,hours,grossPay);
and here is the class WeeklyPayroll
Code:
private String name;
private double hourlyWage;
private int hours;
private double grossPay;
public WeeklyPayroll(){
name = "";
hourlyWage = 0.0;
hours = 0;
grossPay = 0.0;
}
public WeeklyPayroll(String ininame, double inihourlyWage, int inihours, double inigrossPay){
name = ininame;
hourlyWage = inihourlyWage;
hours = inihours;
grossPay = inigrossPay;
}
public double getGrossPay(){
double grossPay = 0.0;
if(hours>40.0){
grossPay = (hours-40.0) * hourlyWage* 1.5+ 40.0 * hourlyWage;
}
else{
grossPay = hourlyWage * hours;
}
return grossPay;
}
Thanks in advanced and I am just starting Java so all criticism is welcome. Sorry for being awful.