So I designed a payroll program. It works like so:
The program prompts you to enter the first name and then prompts you to enter the last name of the employee.
Then it prompts you to enter the employee's skill level. i.e.(skill level 1= 7 dollars per hour, skill level 2= 10 dollars per hour, and skill level 3= 12 dollars per hour)
Finally it prompts you to enter the hours worked. (The employees normal shift is 40 hours per week, if the employee worked more than this then they qualify for overtime pay. Overtime pay is the same amount they make on normal shift.
This is the code:
import javax.swing.JOptionPane; import javax.swing.JFrame; public class PayStuff { public static void main(String[] args) throws Exception { //Declaration of strings String firstName; String lastName; String skillLevel; String durationWorked; firstName= JOptionPane.showInputDialog("Please enter the employee's first name:"); lastName= JOptionPane.showInputDialog("Please enter the employee's last name:"); skillLevel= JOptionPane.showInputDialog("Please enter the employee's skill level:"); int payRate; if (skillLevel.equals("1")) { payRate=7; } else if (skillLevel.equals("2")) { payRate=10; } else if (skillLevel.equals("3")) { payRate=12; } durationWorked= JOptionPane.showInputDialog("Please enter the duration worked in hours:"); int hoursWorked= Integer.parseInt(durationWorked); int normalPay= payRate*hoursWorked; int overtimePay; int grossPay= normalPay+overtimePay; if (hoursWorked <= 40) { overtimePay=0; } else { overtimePay= normalPay; } String stpayRate=Integer.toString(payRate); String stnormalPay=Integer.toString(normalPay); String stovertimePay=Integer.toString(overtimePay); String stgrossPay=Integer.toString(grossPay); JOptionPane.showMessageDialog (null, firstName + lastName + skillLevel + payRate + normalPay + overtimePay + grossPay, "Widget Company Payroll System", JOptionPane.INFORMATION_MESSAGE); { System.exit(0); //Exits the application } } }
I am getting errors. Now I googled this exceptions before attempting to post here:
C:\Program Files\Java\jdk1.6.0_24\bin>javac PayStuff.java PayStuff.java:38: variable payRate might not have been initialized int normalPay= payRate*hoursWorked; ^ PayStuff.java:40: variable overtimePay might not have been initialized int grossPay= normalPay+overtimePay; ^ 2 errors
I understand that when a variable is not initialized, it means that a value has not been assigned to that variable. But if you look I have assigned values to the variables... The other values require the user to input and the other rely on the IF function. Please help