I'm trying to get the below nested statements to work, but am having issues getting them to execute past the first statement. I tried nesting the statements but just the first if executes. Any feedback about formatting is greatly appreciated, I understand that there may be a more efficient way of achieving this, but I have to execute the code using nested statements.
package incometax;
import java.util.Scanner;
import java.text.DecimalFormat;
public class IncomeTax {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
DecimalFormat df = new DecimalFormat ("#,###,000.00");
String singleStatus = "single";
String marriedStatus = "married";
String maritalStatus = "";
double annualIncome = 0;
double taxAmount = 0;
System.out.println("Please enter your martial status: ");
maritalStatus = scnr.next();
if (maritalStatus.compareTo(singleStatus) == 0){
System.out.println("Please enter your annual income: ");
annualIncome = scnr.nextDouble();
if (annualIncome <= 30000){
taxAmount = (annualIncome * .15);
System.out.println("Based on annual income of "+ "$ " +
df.format(annualIncome) + " your tax is " + "$ " +
df.format(taxAmount));
if (annualIncome > 30000){
taxAmount = (annualIncome * .25);
System.out.println("Based on annual income of "+ "$ " +
df.format(annualIncome) +
" your tax is " + "$ " + df.format(taxAmount));
}
}
else {
if (maritalStatus.compareTo(marriedStatus) == 0){
if(annualIncome <= 30000){
taxAmount = (annualIncome * .12);
System.out.println("Based on annual income of "+ "$ "
+ df.format(annualIncome) +
" your tax is " + "$ " + df.format(taxAmount));
if(annualIncome > 30000){
taxAmount = (annualIncome * .20);
System.out.println("Based on annual income of "+
"$ " + df.format(annualIncome) +
" your tax is " + "$ " + df.format(taxAmount));
}
}
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire