Question: I dont understand the error codes I am getting. Could someone help me fix up my code and show me a screenshot of it looking
I dont understand the error codes I am getting. Could someone help me fix up my code and show me a screenshot of it looking at three different tax refunds.
import java.util.Scanner;
public class TaxAccountant {
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);
String output = new String();
output += "Cust. Taxable Federal State Federal State Federal State ";
output += " ID Income Deductions Income Tax Tax W/H W/H Refund Refund ";
output += "===== ====== ========== ======= ======= ===== ======= ===== ======= ====== ";
// Begin first customer
// Get first Customer ID
System.out.println("Enter First Customer ID (-1 To Exit): ");
customerID = Integer.parseInt(input.next()) ;
boolean flag = false;
while (customerID != -1) {
flag = true;
System.out.print("Enter Total Earnings: ");
totalEarnings = input.nextDouble();
System.out.print("Enter Federal Taxes Withheld: ");
federalTaxesWH = input.nextDouble();
System.out.print("Enter State Taxes Withheld: ");
stateTaxWH = input.nextDouble();
System.out.print("Enter Deductions: ");
deductions = input.nextDouble();
// Calculate taxes due/refunds
taxableIncome = totalEarnings - deductions;
if (taxableIncome <= 10000.0) {
federalTax = 0.0;
} else
if (taxableIncome <= 20000.0) {
federalTax = (taxableIncome - 10000.0) * 0.15;
} else if (taxableIncome <= 40000.0) {
federalTax = (taxableIncome - 20000.0) * 0.2 + (0.15 * 10000.0);
} else if (taxableIncome > 40000.0) {
federalTax = (taxableIncome - 40000.0) * 0.3 + (0.2 * 20000.0);
}
stateTax = federalTax * 0.07;
federalRefund = federalTaxesWH - federalTax;
stateRefund = stateTaxWH - stateTax;
// Add data to output String
if (flag) {
output += String.format(
"%4d $%5.0f $%4.0f $%5.0f $%5.0f $%3.0f $%5.0f $%4.0f $%4.0f $%4.0f ",
customerID, totalEarnings, deductions, taxableIncome, federalTax, stateTax, federalTaxesWH,
stateTaxWH, federalRefund, stateRefund);
}
// Get next Customer ID
System.out.print("Enter the next Customer ID (-1 To Exit): ");
int custID = Integer.parseInt(input.next()) ;
if (custID == -1) {
flag = false;
break;
} else {
customerID = custID;
}
}
System.out.println();
// Print out table of data and end program
System.out.print(output);
}
} The Error I am getting is
$javac TaxAccountant.java $java -Xmx128M -Xms16M TaxAccountant Enter First Customer ID (-1 To Exit): Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1371) at TaxAccountant.main(TaxAccountant.java:47)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
