Editing as the problem gets narrowed down:
ans1 = homeMortgage + annualTuition + annualCharity + healthCredit;
if( grossAnnualIncome <= ans1 )
{
System.out.println( "YOU OWE $0.00 IN TAXES!" );
}
else if(grossAnnualIncome == 0)
{
System.out.println( "You earned no income so you owe no taxes!" );
}
else
{
//GROSS ANNUAL INCOME > 0 OUTPUT
System.out.printf( "\nYOUR TAXES\n\n"
+ "Gross Annual Income: %,.0f\n\n"
+ "Deductions: \n"
+ "\tHigher Education: %,.0f\n"
+ "\tCharitable Contributions: %,.0f\n"
+ "\tHome Mortgage Interest: %,.0f\n"
+ "\tHealth Insurance Tax Credit: %,.0f\n\n"
+ "Tax at 17%%: %,.0f\n"
+ "Annual Income After Taxes: %,.0f\n"
+ "Monthly Income After Taxes: %,.0f", grossAnnualIncome, annualTuition, annualCharity,
homeMortgage, healthCredit, taxAt17, annualAfterTaxes, monthlyAfterTaxes);
}
grossAnnualIncome <= ans1 outputs correctly.
grossAnnualIncome == 0 outputs YOU OWE $0.00 IN TAXES! instead of You earned no income so you owe no taxes!
grossAnnualIncome > 0 outputs correctly.
EDIT based on new question…
It’s actually very simple what’s happening here. You’re observing that the statement in the first block is printed. This means that the first test condition was true – that is,
grossAnnualIncome(zero) was less thanans1(also zero in this case).I suspect the way to fix this would be to switch the order of the first two tests, so that the check for zero income takes priority.
In general, if you have conditions that might overlap, make sure you order the tests in an
if - else if - else ...block so that the most specific one appears first.(And by the way, if you’re just outputting a simple string it’s more usual to call
System.out.print(orprintln) rather than printf. No point making Java format nothing after all, and I found it slightly disorienting.)