import java.util.Scanner;
public class Project1_Explore {
public static void main
(String[] args
)
{
// declare variables
int customerID;
double totalEarnings = 0.0;
double federalTaxesWH = 0.0;
double stateTaxWH = 0.0;
double deductions = 0.0;
double taxableIncome = 0.0;
double federalTax = 0.0;
double stateRefund = 0.0;
double stateTax = 0.0;
double federalRefund = 0.0;
// Create a Scanner input object
Scanner input
= new Scanner
( System.
in );
//Create output string
outputString = "Cust. Taxable Federal State Federal State Federal State \n" +
" ID Income Deductions Income Tax Tax W/H W/H Refund Refund\n" +
"===== ====== ========== ======= ======= ===== ======= ===== ======= ======\n";
// "%5d $%6.0f $%.0f $%.0f $%.0f $%.0f $%.0f $%.0f $%.0f $%.0f\n"
// Begin first customer
System.
out.
println( "Welcome to the Tax Account Program!\n"
+ "Begin by entering the Customer ID: " );
// Get first Customer ID
customerID = input.nextInt();
while( customerID != -1 )
{
// Get income and withholding information
System.
out.
println( "Enter Total Earnings for customer: " );
totalEarnings = input.nextFloat();
System.
out.
println( "Enter Federal Taxes Withheld: " );
federalTaxesWH = input.nextFloat();
System.
out.
println( "Enter State Taxes Withheld: " );
stateTaxWH = input.nextFloat();
System.
out.
println( "Enter Deductions: " );
deductions = input.nextFloat();
// Calculate taxes due/refunds
taxableIncome = totalEarnings - deductions;
if( taxableIncome >= 0 && taxableIncome <= 10000 )
{
federalTax = 0.0;
}
if( taxableIncome >= 10001 && taxableIncome <= 20000 )
{
federalTax = ( taxableIncome - 10000) * (.15 );
}
if( taxableIncome >= 20001 && taxableIncome <= 40000 )
{
federalTax = 1500 + ( taxableIncome - 20000 ) * ( .2 );
}
if( taxableIncome > 40000 )
{
federalTax = 5500 + ( taxableIncome - 40000 ) * ( .3 );
}
stateTax = ( federalTax * .07 );
federalRefund = federalTaxesWH - federalTax;
stateRefund = stateTaxWH - stateTax;
//create strings for output string formatting
String taxableIncomeCur
= String.
format("$%.0f", taxableIncome
);
String federalRefundCur
= String.
format("$%.0f", federalRefund
);
String stateRefundCur
= String.
format("$%.0f", stateRefund
);
String totalEarningsCur
= String.
format("$%.0f", totalEarnings
);
String federalTaxesWHCur
= String.
format("$%.0f", federalTaxesWH
);
//format dataString to add to outputString
+ "%6s %6s %4s %6s %5s %5s %5s \n", customerID,
totalEarningsCur, deductionsCur,
taxableIncomeCur, federalTaxCur, stateTaxCur, federalTaxesWHCur,
stateTaxWHCur, federalRefundCur, stateRefundCur);
// Add data to output String
outputString = outputString + dataString;
// Get next Customer ID
System.
out.
println("Enter next Customer ID or press -1 "
+ "to print data:");
customerID = input.nextInt();
}
// Print out table of data and end program
System.
out.
print(outputString
);
}
}