I am trying to calculate this if/else statement through the JOption Message window. Prompt 1 is fine and returns the name, but I am not getting any calculations through prompt 2. I’m guessing I need to do something with my double number1, but I’m not exactly sure.
Thanks in advance!
public static void main(String[] args)
{
Scanner imput = new Scanner(System.in); //ALLOW USER TO INPUT NAME AND MONTHLY INCOME
long monthlyIncome = 0;
double newSocSecTax = 0.0;
double oldSocSecTax = 0.0;
String name = JOptionPane.showInputDialog( "Please enter your name: "); //PROMPT 1
String income = JOptionPane.showInputDialog("\nPlease enter your gross monthly income: "); //PROMPT 2
double number1 = Double.parseDouble( income );
if(monthlyIncome >= 110100.00)
{
newSocSecTax = 110100.00 * .062;
oldSocSecTax = 106800.00 * .042;
}
else
{
if(monthlyIncome >= 106800.00)
{
newSocSecTax = monthlyIncome * .062;
oldSocSecTax = 106800.00 * .042;
}
else
{
newSocSecTax = monthlyIncome * .062;
oldSocSecTax = monthlyIncome * .042;
}
}
String message = String.format( "%s, your monthly social security tax will be $%.2f." +
"\nThis is an increase of $%.2f.", name, newSocSecTax, oldSocSecTax );
JOptionPane.showMessageDialog( null, message );
System.exit(0);
}
}
Change your code to
because in
if-elsestatement you are usingmonthlyIncomebut in your original code you assigned the value tonumber1