Determines the tax rate and computes the tax to pay

Assignment Help Basic Computer Science
Reference no: EM131738821

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;

  }

Reference no: EM131738821

Questions Cloud

Five database management challenges in cloud environment : Discuss five database management challenges in cloud environment and the proposed techniques to overcome them five.
Essential management concepts and perspectives : You have studied some essential management concepts and perspectives through presentations by your teacher from your university.
Limitations on state police powers : Describe the five factual situations wherein the commerce clause might be used to restrict a state or local governmental action.
The topic of emerging enterprise network applications : Research at least two articles on the topic of emerging enterprise network applications. Write a brief synthesis and summary of the two articles.
Determines the tax rate and computes the tax to pay : The program below repeatedly asks the user to enter an annual salary, stopping when the user enters 0 or less. For each annual salary
Define would you make it the arab-israeli conflict : Would you make it the Arab-israeli conflict? tell me why or why not and a support your answer by going through the different conflict types
Necessary to achieve success with loyalty programs : What linking mechanisms do you believe are necessary to achieve success with loyalty programs?
Define the terms apportionment and nexus : How are these concepts applied to restrict state government taxation of businesses engaged in interstate commerce?
Explain some of the key elements of an incident : You have tasked the IT department with developing an incident response plan to address risks to the information system.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd