package ch5;
import javax.swing.JOptionPane;
public class Nested
{
private boolean married;
private double income, tax;
// single: 10% up to $32,000, then 25%
// married: 10% up to $64,000, then 25%
private void findTax()
{ String incomeStr = JOptionPane.showInputDialog("Income?");
income = Double.parseDouble(incomeStr);
married = true;
if (! married)
{ if (income <= 32000)
{ tax = income * 0.1;
}
else
{ tax = 0.1 * 32000 + (income - 32000)*0.25;
}
}
else
if (income <= 64000)
{ tax = income * 0.1;
}
else
{ tax = 0.1 * 64000 + (income - 64000) * 0.25;
}
String msg = "With an income = $" + income + " and married = " + married;
msg += "\nyour tax = "+tax;
JOptionPane.showMessageDialog(null, msg);
}
public static void main(String[] args)
{ Nested n = new Nested();
n.findTax();
}
}