Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A program may execute the same computations repeatedly. The program below repeatedly asks the user to enter an annual salary, stopping when the user enters
A program may execute the same computations repeatedly.
The program below repeatedly asks the user to enter an annual salary, stopping when the user enters or less. For each annual salary, the program determines the tax rate and computes the tax to pay.
Run the program below with annual salaries of and then
Modify the program to use a while loop inside the given while loop. The new inner loop should repeatedly ask the user to enter a salary deduction, stopping when the user enters a or less. The deductions are summed and then subtracted from the annual income, giving an adjusted gross income. The tax rate is then calculated from the adjusted gross income.
Run the program with the following input: and Note that the and are deductions.
Note: The calculation is inaccurate to how taxes are formally assessed and is a simplification for educational purposes only.
import java.util.Scanner;
public class IncomeTax
public static void main String args
Scanner scnr new ScannerSystemin;
final String SALARYPROMPT
Enter annual salary to exit: ;
int annualSalary;
int deduction;
int totalDeductions;
double taxRate;
int taxToPay;
System.out.printlnSALARYPROMPT;
annualSalary scnrnextInt;
while annualSalary
FIXME: Add a while loop to gather deductions. Use the variables
deduction and totalDeduction for deduction handling.
End the inner while loop when a deduction is entered.
Determine the tax rate from the annual salary
if annualSalary
taxRate ; is written as a decimal
else if annualSalary
taxRate ;
else if annualSalary
taxRate ;
else
taxRate ;
taxToPay intannualSalary taxRate; Truncate tax to an integer amount
System.out.printlnAnnual salary: annualSalary;
System.out.printlnTax rate: taxRate;
System.out.printlnTax to pay: taxToPay;
Get the next annual salary
System.out.printlnSALARYPROMPT;
annualSalary scnrnextInt;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started