Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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 0 or less. For each annual salary, the program determines the tax rate and computes the tax to pay.

  1. Run the program below with annual salaries of 40000, 90000, and then 0.
  2. 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 0 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.
  3. Run the program with the following input: 40000, 7000, 2000, 0, and 0. Note that the 7000 and 2000 are deductions

import java.util.Scanner;

public class IncomeTax {

  public static void main (String [] args) {

     Scanner scnr = new Scanner(System.in);

     final String SALARY_PROMPT = "nEnter annual salary (0 to exit): ";

     int   annualSalary   = 0;

     int   deduction      = 0;

     int   totalDeductions = 0;

     double taxRate        = 0.0;

     int   taxToPay       = 0;

     System.out.println(SALARY_PROMPT);

     annualSalary = scnr.nextInt();

     while (annualSalary > 0) {

        // 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 <= 0 is entered.

        // Determine the tax rate from the annual salary

        if (annualSalary <= 20000) {

           taxRate = 0.10;       // 0.10 is 10% written as a decimal

        }

        else if (annualSalary <= 50000) {

           taxRate = 0.20;

        }

        else if (annualSalary <= 100000) {

           taxRate = 0.30;

        }

        else {

           taxRate = 0.40;

        }

        taxToPay = (int)(annualSalary * taxRate);  // Truncate tax to an integer amount

        System.out.println("Annual salary: " + annualSalary);

        System.out.println("Tax rate: " + taxRate);

        System.out.println("Tax to pay: " + taxToPay);

        // Get the next annual salary

        System.out.println(SALARY_PROMPT);

        annualSalary = scnr.nextInt();

     }

     return;

  }

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92550390
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Will anyone help me with this and give me the explain how

Will anyone help me with this and give me the explain how did you get the answer? No coding necessary. Give truth tables for each the following Boolean expressions. a) not (P and Q) b) (not P) and Q c) (not P) or (not Q) ...

Question draw a map labeling every aspect which represents

Question: Draw a map, labeling every aspect, which represents how IP addressing works with DNS servers to process a request for a web page from your computer that returns the web page.Using tracert from your terminal ent ...

Questionimplement a calculator for a client-server

Question Implement a calculator for a client-server architecture using socket communication between the client and the server. The client should provide the graphical user interface for the user, and the server should pe ...

Identify and evaluate at least three considerations that

Identify and evaluate at least three considerations that one must plan for when designing a database. Suggest at least two types of databases that would be useful for small businesses, two types for regional level organi ...

Command to mail only the process id of running java program

Command to mail only the process ID of running Java program test to the email address (single line Unix)

Task 1 use the sumofnnumbersjava file create a method that

Task 1: Use the sumOf_N_Numbers.java file. Create a method that takes in two parameters namely the starting and ending number of the range and returns the sum of all the numbers in that range to the calling method Task 2 ...

Suppose that you sample 59 high school baseball pitchers in

Suppose that you sample 59 high school baseball pitchers in one county and find that they have a mean fastball pitching speed of 80.00 miles per hour (mph) with a standard deviation of 4.98 mph. Find a 95% confidence int ...

Legacy industries inc has a historic pe multiple of 15 a

Legacy Industries Inc. has a historic P/E multiple of 15, a current EPS of $2.50 projected to grow by 4% in the coming year, and a forward looking P/E multiple of 18. With this information please estimate the current pri ...

Research the fire at the federal aviation administration

Research the fire at the Federal Aviation Administration (FAA) facility in Chicago, Illinois (2014). Provide insight into the following: What went wrong? What went right? Would a risk assessment strategy if employed miti ...

How does the learning environment effect the success of

How does the learning environment effect the success of students? Provide examples.

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As