Hi all,
Having another problem with a program. I thought i had this one pretty good, i was confident about it, but no luck. The problem was with initializing a variable, i try to add in to output what the variable is and it says it needs to might not have been initialized. Im not sure if the problem is that i tried to initialize it inside an if statement or if i have this overloaded and its too much for it to handle. I would much appreciate any help on this one. Here is my code:
import javax.swing.JOptionPane;
public class ComputeNet
{
public static void main(String[] args)
{
String rateString;
String hourString;
double rate;
double hours;
double grossPay;
double withholding;
double netPay;
int withholding1;
rateString = JOptionPane.showInputDialog(null,
"How much do you make per hour?");
hourString = JOptionPane.showInputDialog(null,
"How many hours did you work this week?");
rate = Double.parseDouble(rateString);
hours = Double.parseDouble(hourString);
grossPay = rate * hours;
if(grossPay <= 300)
{
withholding = .10;
netPay = grossPay - (grossPay * withholding);
withholding1 = 10;
}
else
{
if(grossPay >= 300.01)
{
withholding = .12;
netPay = grossPay - (grossPay * withholding);
withholding1 = 12;
}
JOptionPane.showMessageDialog(null,
"Your gross pay is " + grossPay +
", Your withholding is " + withholding1 +
", and your net pay is " + netPay);
System.exit(0);
}
}
}
Thanks much,
Sam