-
-
Save Chris--B/3680935 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DecimalFormat; | |
import java.util.Scanner; | |
/* P2 | |
* Mindy Mach | |
* w/ changes by Chris | |
*/ | |
public class P2 { | |
public static void main(String[] args) { | |
/* | |
* Variable names should be easy to identify. "t" is a terrible name for just about anything. | |
* These names should be self-explanatory, so there's no need to ask "what does tot mean? Total Taxes?" | |
*/ | |
int exemptions; | |
double grossSalary, charity, capitalGains, interestIncome, totalIncome, adjustedIncome; | |
double taxes = 0.0; //this is initialized because we need might/will add to it later, while the others are just set. | |
//Scanner initialization | |
Scanner keyboard = new Scanner(System.in); | |
System.out.print("Number of Exemptions: "); | |
exemptions = keyboard.nextInt(); | |
System.out.print("Gross Salary: "); | |
grossSalary = keyboard.nextDouble(); | |
System.out.print("Interest income: "); | |
interestIncome = keyboard.nextDouble(); | |
System.out.print("Capital Gains: "); | |
capitalGains = keyboard.nextDouble(); | |
System.out.print("Charitable Contributions: "); | |
charity = keyboard.nextDouble(); | |
totalIncome = (grossSalary + interestIncome + capitalGains); | |
System.out.println("Total Income: $" + totalIncome); | |
System.out.println("Adjusted Income: $" + (totalIncome-(exemptions *1500)- charity)); | |
//adjustedIncome is no longer declared down here. It's up at the top with its friends. | |
adjustedIncome = (totalIncome-(exemptions *1500)- charity); | |
if( adjustedIncome > 10000) | |
{ | |
if( adjustedIncome < 32000) | |
{ | |
/* Instead of using temporary variables A, B, and C, and then adding them | |
* together to set taxes (previous tot), just add directly to taxes. | |
*/ | |
taxes += (adjustedIncome - 10000) * 0.15; | |
} | |
else | |
{ | |
taxes += (22000 * 0.15); | |
} | |
} | |
if (adjustedIncome > 32000) | |
{ | |
if(adjustedIncome < 50000) | |
{ | |
taxes += (adjustedIncome - 32000) * 0.23; | |
} | |
else | |
{ | |
taxes += 18000 * 0.23; | |
} | |
} | |
if (adjustedIncome > 50000) | |
{ | |
taxes += (adjustedIncome - 50000) * 0.28; | |
} | |
DecimalFormat fmt = new DecimalFormat("#.00"); | |
System.out.println("Total Tax: $" + fmt.format(taxes)); | |
//close the Scanner after we're done with it. | |
keyboard.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment