I'm trying to complete this assignment:
Assignment: FooCorporation
Method to print pay based on base pay andhours worked
Overtime: More than 40 hours, paid 1.5 times base pay
Minimum Wage: $8.00/hour
Maximum Work: 60 hours a week
Here's what I have written:
package printpay;
/**
*
* @author Ashley
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void calculatePay(int x){
int baseWage = 8;
double overtimePay;
if (x>60){
x=60;
}
if(x>40){
int overtimeHours = x-40;
overtimePay = overtimeHours*1.5*baseWage;
x = 40;
}
double regularPay = x*8;
double totalPay = regularPay+overtimePay;
System.out.println(totalPay);
}
public static void main(String[] args) {
int hoursWorked = 55;
calculatePay(hoursWorked);
}
}
However, in the line where I combine the overtime pay and the standard pay, I get an error that the overtime pay variable might not be initialized. I think this has something to do with scope of variables. Could someone please help me out?