I'm doing this java homework of finding the tax income based on marital status using the if else statements and joptionpane. The issue is after getting the tax and marital status inputs the output doesn't show up it just terminates the program. There no errors also.
I tried putting a semicolon after the first if statements and it somehow works but it shows 2 different outputs instead of 1
public class Program_4_2 {
public static void main (String[] args) {
String status;
String tax;
double tax_income;
status = JOptionPane.showInputDialog("Please enter s for single, m for married: ");
tax = JOptionPane.showInputDialog("Enter Your Tax Income: ");
tax_income = Double.parseDouble(tax);
// SINGLE TAX;
if (status == "s")
{
if (tax_income > 0 && tax_income < 8000)
{
tax_income = tax_income * 0.1 + 0;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
else if (tax_income > 8000 && tax_income < 32000)
{
tax_income = (tax_income - 8000) * 0.15 + 800;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
else if (tax_income > 32000)
{
tax_income = (tax_income - 32000) * 0.25 + 4400;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
}
// Married Tax
if (status == "m")
{
if (tax_income > 0 && tax_income < 16000)
{
tax_income = tax_income * 0.1 + 0;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
else if (tax_income > 16000 && tax_income < 64000)
{
tax_income = (tax_income - 16000) * 0.15 + 1600;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
else if (tax_income > 64000)
{
tax_income = (tax_income - 64000) * 0.25 + 8800;
JOptionPane.showMessageDialog(null, "Your Tax is " + tax_income);
}
}
}
}
An example output would be :
user input status -> "s" -> user then inputs tax -> "9000" -> output should show -> "950" or "900" if the status input is m