Big Java Late Objects
Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 3.4, Problem 19SC
Program Plan Intro

Given Program:

The program given in the textbook is given here with comments for better understanding.

File Name: TaxReturn.java

// Class definition

public class TaxReturn

{

    // Declare and initialize the required variables

    public static final int SINGLE = 1;

    public static final int MARRIED = 2;

    private static final double RATE1 = 0.10;

    private static final double RATE2 = 0.25;

    private static final double RATE1_SINGLE_LIMIT = 32000;

    private static final double RATE1_MARRIED_LIMIT = 64000;

    private double income;

    private int status;

/*Constructs a TaxReturn object for a given income and marital status.

  @param anIncome the taxpayer income

  @param aStatus either SINGLE or MARRIED */

    // Method definition

    public TaxReturn(double anIncome, int aStatus)

    {

        income = anIncome;

        status = aStatus;

    }

    // Method definition

    public double getTax()

    {

        // Declare and initialize the required variables

        double tax1 = 0;

        double tax2 = 0;

/* If the entered status is "Single", compute income tax based on their income */

        if (status == SINGLE)

        {

/* Check whether the income is less than or equal to $32000 */

            if (income <= RATE1_SINGLE_LIMIT)

            {

                // If it is, compute the tax

                tax1 = RATE1 * income;

            }

/* If the income is greater than or equal to $32000, compute the tax */

            else

            {

                tax1 = RATE1 * RATE1_SINGLE_LIMIT;

                tax2 = RATE2 * (income - RATE1_SINGLE_LIMIT);

            }

        }

/* If the entered status is "Married", compute income tax based on their income */

        else

        {

/* Check whether the income is less than or equal to $64000 */

            if (income <= RATE1_MARRIED_LIMIT)

            {

                // If it is, compute the tax

                tax1 = RATE1 * income;

            }

/* If the income is greater than or equal to $64000, compute the tax */

            else

            {

                tax1 = RATE1 * RATE1_MARRIED_LIMIT;

tax2 = RATE2 * (income - RATE1_MARRIED_LIMIT);

            }

        }

        // Return the tax to the main function

        return tax1 + tax2;

    }

}

File Name: TaxCalculator.java

// Import the required package

import java.util.Scanner;

/**

This program calculates a simple tax return.

 */

// Class definition

public class TaxCalculator

{

    // Main class declaration

    public static void main(String[] args)

    {

        // Create an object for scanner class

        Scanner in = new Scanner(System.in);

        // Prompt the user to enter the income

        System.out.print("Please enter your income: ");

        // Store the entered income in the variable

        double income = in.nextDouble();

        // Prompt the user to enter marital status

        System.out.print("Are you married? (Y/N) ");

        // Store the entered value in a variable

        String input = in.next();

        // Declare the variable

        int status;

/* Check whether the user input value for marital status is "Y" */

        if (input.equals("Y"))

        {

/* If it is "Y", store the taxreturn value for a married person in the variable */

            status = TaxReturn.MARRIED;

        }

/* Check whether the user input value for marital status is "N" */

        else

        {

/* If it is "N", store the taxreturn value for a single person in the variable */

            status = TaxReturn.SINGLE;

        }

        // Create an object for TaxReturn class

        TaxReturn aTaxReturn = new TaxReturn(income, status);

        // Display the tax return value based on the user input

        System.out.println("Tax: "

                + aTaxReturn.getTax());

    }

}

Blurred answer
Students have asked these similar questions
Suppose, you are working in a company ‘X’ where your job is to calculate the profit based on their investment.If the company invests 100,000 USD or less, their profit will be based on 75,000 USD as first 25,000 USD goes to set up the business in the first place. For the first 100,000 USD, the profit margin is low: 4.5%. Therefore, for every 100 dollar they spend, they get a profitof 4.5 dollar.For an investment greater than 100,000 USD, for the first 100,000 USD (actually on 75,000 USD as 25,000 is the setup cost), the profit margin is 4.5% where for the rest, it goes up to 8%. For example, if they invest 250,000 USD, they will get an 8% profit for the 150,000 USD. In addition, from the rest 100,000 USD, 25,000 is the setup cost and there will be a 4.5% profit on the rest 75,000. Investment will always be greater or equal to 25,000 and multiple of 100.Complete the RECURSIVE methods below that take an array of integers (investments)and an iterator (always sets to ZERO(‘0’) when the…
Suppose, you are working in a company ‘X’ where your job is to calculate the profit based  on their investment.   If the company invests 100,000 USD or less, their profit will be based on 75,000 USD as  first 25,000 USD goes to set up the business in the first place. For the first 100,000 USD,  the profit margin is low: 4.5%. Therefore, for every 100 dollar they spend, they get a profit  of 4.5 dollar.  For an investment greater than 100,000 USD, for the first 100,000 USD (actually on 75,000  USD as 25,000 is the setup cost), the profit margin is 4.5% whereas for the rest, it goes up to  8%. For example, if they invest 250,000 USD, they will get an 8% profit for the 150,000  USD. In addition, from the rest 100,000 USD, 25,000 is the setup cost and there will be a  4.5% profit on the rest 75,000. The investment will always be greater or equal to 25,000 and multiple of 100.  Complete the RECURSIVE methods below that take an array of integers (investments)  and an iterator (always sets to…
Suppose, you are working in a company ‘X’ where your job is to calculate the profit based  on their investment.   If the company invests 100,000 USD or less, their profit will be based on 75,000 USD as  first 25,000 USD goes to set up the business in the first place. For the first 100,000 USD,  the profit margin is low: 4.5%. Therefore, for every 100 dollar they spend, they get a profit  of 4.5 dollar.  For an investment greater than 100,000 USD, for the first 100,000 USD (actually on 75,000  USD as 25,000 is the setup cost), the profit margin is 4.5% where for the rest, it goes up to  8%. For example, if they invest 250,000 USD, they will get an 8% profit for the 150,000  USD. In addition, from the rest 100,000 USD, 25,000 is the setup cost and there will be a  4.5% profit on the rest 75,000. Investment will always be greater or equal to 25,000 and  multiple of 100.  Complete the RECURSIVE methods below that take an array of integers (investments)  and an iterator (always sets to…

Chapter 3 Solutions

Big Java Late Objects

Ch. 3.3 - In a game program, the scores of players A and B...Ch. 3.3 - Prob. 12SCCh. 3.3 - Prob. 13SCCh. 3.3 - Beginners sometimes write statements such as the...Ch. 3.3 - Prob. 15SCCh. 3.3 - Suppose we want to have the earthquake program...Ch. 3.4 - Prob. 17SCCh. 3.4 - Would that amount change if the first nested if...Ch. 3.4 - Prob. 19SCCh. 3.4 - Prob. 20SCCh. 3.4 - Prob. 21SCCh. 3.5 - Draw a flowchart for a program that reads a value...Ch. 3.5 - Prob. 23SCCh. 3.5 - Prob. 24SCCh. 3.5 - Draw a flowchart for a program that reads a value...Ch. 3.5 - Draw a flowchart for a program that reads a value...Ch. 3.6 - Prob. 27SCCh. 3.6 - Prob. 28SCCh. 3.6 - Prob. 29SCCh. 3.6 - Suppose you are designing a part of a program for...Ch. 3.7 - Suppose x and y are two integers. How do you test...Ch. 3.7 - How do you test whether at least one of them is...Ch. 3.7 - How do you test whether exactly one of them is...Ch. 3.7 - Prob. 34SCCh. 3.7 - What is the advantage of using the type boolean...Ch. 3.8 - In the ElevatorSimulation2 program, what is the...Ch. 3.8 - Your task is to rewrite lines 1926 of the...Ch. 3.8 - In the Sherlock Holmes story The Adventure of the...Ch. 3.8 - Prob. 39SCCh. 3 - What is the value of each variable after the if...Ch. 3 - Prob. 2RECh. 3 - Find the errors in the following if statements. a....Ch. 3 - What do these code fragments print? a. int n = 1;...Ch. 3 - Suppose x and y are variables of type double....Ch. 3 - Suppose x and y are variables of type double....Ch. 3 - Explain why it is more difficult to compare...Ch. 3 - Given two pixels on a computer screen with integer...Ch. 3 - It is easy to confuse the - and operators. Write...Ch. 3 - Each square on a chess board can be described by a...Ch. 3 - Prob. 11RECh. 3 - In a scheduling program, we want to check whether...Ch. 3 - Draw a flowchart for the algorithm in Exercise...Ch. 3 - Draw a flowchart for the algorithm in Exercise...Ch. 3 - Draw a flowchart for the algorithm in Exercise...Ch. 3 - Prob. 16RECh. 3 - Prob. 17RECh. 3 - Write pseudocode for a program that prompts the...Ch. 3 - Write pseudocode for a program that assigns letter...Ch. 3 - Explain how the lexicographic ordering of strings...Ch. 3 - Of the following pairs of strings, which comes...Ch. 3 - Explain the difference between an if/else if/else...Ch. 3 - Give an example of an if/else if/else sequence...Ch. 3 - Rewrite the condition in Section 3.3 to use ...Ch. 3 - Prob. 25RECh. 3 - Make up a Java code example that shows the...Ch. 3 - Complete the following truth table by finding the...Ch. 3 - True or false? A B is the same as B A for any...Ch. 3 - The advanced search feature of many search engines...Ch. 3 - Suppose the value of b is false and the value of x...Ch. 3 - Simplify the following expressions. Here, b is a...Ch. 3 - Simplify the following statements. Here, b is a...Ch. 3 - What is wrong with the following program?...Ch. 3 - Write a program that reads an integer and prints...Ch. 3 - Write a program that reads a floating-point number...Ch. 3 - Write a program that reads an integer and prints...Ch. 3 - Write a program that reads three numbers and...Ch. 3 - Write a program that reads three numbers and...Ch. 3 - Repeat Exercise E3.5, but before reading the...Ch. 3 - Write a program that reads in three integers and...Ch. 3 - Write a program that reads four integers and...Ch. 3 - A compass needle points a given number of degrees...Ch. 3 - Write a program that reads a temperature value and...Ch. 3 - The boiling point of water drops by about one...Ch. 3 - Add error handling to Exercise E3.11. If the user...Ch. 3 - When two points in time are compared, each given...Ch. 3 - The following algorithm yields the season (Spring,...Ch. 3 - Write a program that reads in two floating-point...Ch. 3 - Unit conversion. Write a unit conversion program...Ch. 3 - Write a program that prompts the user to provide a...Ch. 3 - Write a program that asks the user to enter a...Ch. 3 - Write a program that translates a letter grade...Ch. 3 - Write a program that translates a number between 0...Ch. 3 - Write a program that takes user input describing a...Ch. 3 - Write a program that reads in three floating-point...Ch. 3 - Write a program that reads in three strings and...Ch. 3 - Write a program that prompts for the day and month...Ch. 3 - The original U.S. income tax of 1913 was quite...Ch. 3 - Write a program that computes taxes for the...Ch. 3 - The TaxReturn.java program uses a simplified...Ch. 3 - Write a program that reads in the x- and...Ch. 3 - Write a program that reads in the x- and...Ch. 3 - Write a program that reads in the x- and...Ch. 3 - Roman numbers. Write a program that converts a...Ch. 3 - A year with 366 days is called a leap year. Leap...Ch. 3 - French country names are feminine when they end...Ch. 3 - Write a program to simulate a bank transaction....Ch. 3 - Write a program that reads in the name and salary...Ch. 3 - When you use an automated teller machine (ATM)...Ch. 3 - Calculating the tip when you go to a restaurant is...Ch. 3 - A supermarket awards coupons depending on how much...Ch. 3 - Write a program that prompts the user for a...Ch. 3 - Repeat Exercise P3.21, modifying the program so...Ch. 3 - Repeat Exercise P3.21, modifying the program so...Ch. 3 - A minivan has two sliding doors. Each door can be...Ch. 3 - Sound level L in units of decibel (dB) is...Ch. 3 - The electric circuit shown below is designed to...Ch. 3 - Crop damage due to frost is one of the many risks...Ch. 3 - A mass m = 2 kilograms is attached to the end of a...Ch. 3 - The average person can jump off the ground with a...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole