Note that there are some explanatory texts on larger screens.

plurals
  1. PONot exactly sure how to initialize these variables
    text
    copied!<p>The piece of code I am supposed to write is a Payroll program that gathers users inputs and then will output payroll information. I have wrote the program, but I cannot seem to figure out why I am getting the error "the local variables may not have been initialized. </p> <pre><code>import javax.swing.JOptionPane; public class Payroll { public static void main(String []args) { String name, rateStr, hoursStr, maritalStatus, deductionStr, numEmpStr; double numEmp, rateOfPay, hoursWorked, regularPay, overtimeHours, overtimePay, insuranceRate, taxRate, grossPay, taxes, deduction, netPay; final double taxRate1 = .0857; final double taxRate2 = .0756; final double taxRate3 = .0579; numEmpStr = JOptionPane.showInputDialog("How many employees do you have? "); numEmp = Double.parseDouble(numEmpStr); while(numEmp &gt;0 ) { //Input All User Info! name = JOptionPane.showInputDialog("Employee Name: "); rateStr = JOptionPane.showInputDialog("Rate of Pay: "); rateOfPay = Double.parseDouble(rateStr); hoursStr = JOptionPane.showInputDialog("Hours Worked: "); hoursWorked = Double.parseDouble(hoursStr); deductionStr = JOptionPane.showInputDialog("Number of Deductions (Enter 1 or 2): "); deduction = Double.parseDouble(deductionStr); maritalStatus = JOptionPane.showInputDialog("Marital Status (M - Married, S - Single): "); //if statement (if hoursWorked &gt;40 if(hoursWorked&gt; 40) { overtimeHours = (hoursWorked - 40); overtimePay = (rateOfPay*1.5*overtimeHours); regularPay = (40*rateOfPay); grossPay = (regularPay + overtimePay); } else { grossPay = (rateOfPay*hoursWorked); } if(maritalStatus == "M" ) { insuranceRate = 50; } else { insuranceRate = 75; } if(deduction&gt;2) { taxRate = .0579; } else if(deduction==2) { taxRate = .0759; } else if(deduction==1) { taxRate = .0857; } else { } taxes = (grossPay*taxRate); netPay = (grossPay - (taxes + insuranceRate)); JOptionPane.showMessageDialog(null, "Name: " + name + "\nRate of Pay: " + rateOfPay + "\nHours Worked: " + hoursWorked + "\nRegular Pay: " + regularPay + "\nOvertime Pay: " + overtimePay + "\nGross Pay: " + grossPay + "\nTax Rate: " + taxRate + "\nTaxes: " + taxes + "\nInsurance Status: " + maritalStatus + "\nDeductions: " + insuranceRate + "\nNet Pay: " + netPay); --numEmp; } JOptionPane.showMessageDialog(null, "Your are finished with payroll for this period."); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload