Here is the code I have for a tax program.Is there a better way to structure the if else statements and also is there a better way to write the program. I apologize before hand for not having any comments.
package jOptionPane;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args)
{
double paycheck = Double.parseDouble(JOptionPane.showInputDialog("How much was your paycheck?"));
String[] options = new String[] {"Yes", "No"};
int response = JOptionPane.showOptionDialog(null, "Are you married?", "Title",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, options, options[0]);
double deductions = Integer.parseInt(JOptionPane.showInputDialog("How many deductions did you claim?"));
String[] payOften = new String[] {"Weekly", "Biweekly"};
int variability = JOptionPane.showOptionDialog(null, "How often do you get paid?", "Title",
JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE,
null, payOften, payOften[0]);
double SS = 0;
if (response == 0)
{
if (variability == 0)
{
if(paycheck <= 490)
{
SS = (paycheck - (deductions*73.08)) * .1;
}
else if (paycheck <= 1515)
{
SS = (paycheck - (deductions*73.08)) * .15 + 33.4;
}
else
{
System.out.println("I am too lazy to compute");
}
}
else
{
if(paycheck <= 981)
{
SS = (paycheck - (deductions * 146.15)) * .1;
}
else if (paycheck <= 3031)
{
SS = (paycheck - (deductions * 146.15)) * .15 + 66.9;
}
else
{
System.out.println("I am too lazy to compute");
}
}
}
else
{
if (variability == 0)
{
if(paycheck <= 209)
{
SS = (paycheck - (deductions * 73.08)) * .1;
}
else if (paycheck <= 721)
{
SS = (paycheck -(deductions * 73.08)) * .15 + 16.8;
}
else
{
System.out.println("I am too lazy to compute.");
}
}
else
{
if(paycheck <= 417)
{
SS = (paycheck - (deductions * 146.15)) * .1;
}
else if (paycheck <= 1442)
{
SS = (paycheck - (deductions * 146.15)) * .15 + 33.4;
}
else
{
System.out.println("I am too lzy to compute.");
}
}
}
System.out.println("You owe " + SS + " for Social Security");
}
}
Aucun commentaire:
Enregistrer un commentaire