Java: An Introduction to Problem Solving and Programming (7th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 6, Problem 1E
Expert Solution & Answer
Check Mark
Program Plan Intro

Tax computation

Program plan:

  • • Define the class “TaxComputer”.
    • ○ Declare the necessary constant variables.
    • ○ Define the method “changeBasicRateTo()”.
      • ■ Assign “newRate” into the variable “basicRate”.
    • ○ Define the method “changeLuxuryRateTo()”.
      • ■ Assign “newRate” into the variable “luxuryRate”.
    • ○ Define the method “computeCostBasic()”.
      • ■ Calculate “tax”, and “price”.
      • ■ Return the value.
    • ○ Define the method “computeCostLuxury()”.
      • ■ Calculate “tax”, and “price”.
      • ■ Return the value.
    • ○ Define the method “roundToNearestPenny()”.
      • ■ Calculate the price.
      • ■ Return the value.
    • ○ Define the “main()” function.
      • ■ Print the result by calling the appropriate methods.
Program Description Answer

Program to display the tax computation of the computer.

Explanation of Solution

Program:

//Define the class

public class TaxComputer

{

    //Declare the necessary constant variables

    private static double basicRate = 4.0;

    private static double luxuryRate = 10.0;

    //Define the function changeBasicRateTo()

    public static void changeBasicRateTo(double newRate)

    {

/*Assign "newRate" into the variable “basicRate”*/

        basicRate = newRate;

    }

    //Define the function changeLuxuryRateTo()

    public static void changeLuxuryRateTo(double newRate)

    {

/*Assign "newRate" into the variable “luxuryRate”*/

        luxuryRate = newRate;

    }

    //Define the function computeCostBasic()

    public static double computeCostBasic(double price)

    {

        //Calculate the “tax”

        double tax = price * basicRate / 100;

        //Calculate the “price”

        price = price + tax;

        //Return the value

        return roundToNearestPenny(price);

    }

    //Define the function computeCostLuxury()

    public static double computeCostLuxury(double price)

    {

        //Calculate the "tax"

        double tax = price * luxuryRate / 100;

        //Calculate the "price"

        price = price + tax;

        //Return the value

        return roundToNearestPenny(price);

    }

    //Define the function roundToNearestPenny()

private static double roundToNearestPenny(double price)

    {

        //Calculate the "price"

        price = price * 100;

        price = java.lang.Math.round(price);

        //Return the value

        return price/100;

    }

    //Define the main() function

    public static void main(String[] args)

    {

        //Print the statement

        System.out.println("Testing the basic rate computation.");

        //Print the statement

        System.out.println(" Item price no tax:10.00");

        //Print the statement

    System.out.println("cost with 4% tax: "+ TaxComputer.computeCostBasic(10.00));

        //Print the statement

        System.out.println("Testing the basic rate computation.");

        //Call the function changeBasicRateTo()

        TaxComputer.changeBasicRateTo(7.5);

        //Print the statement

        System.out.println(" Item price no tax: 10.00");

        //Print the statement

        System.out.println("cost with 7.5% tax: "+ TaxComputer.computeCostBasic(10.00));

        //Print the statement

        System.out.println("Testing the luxury rate computation.");

        //Print the statement

        System.out.println(" Item price no tax: 2019.25");

        //Print the statement

        System.out.println("cost with 10% tax: "+ TaxComputer.computeCostLuxury(2019.25));

        //Print the statement

        System.out.println("Testing the luxury rate computation.");

        //Call the function changeLuxuryRateTo()

        TaxComputer.changeLuxuryRateTo(20.0);

        //Print the statement

        System.out.println(" Item price no tax: 2019.25");

        //Print the statement

        System.out.println("cost with 20% tax: "+ TaxComputer.computeCostLuxury(2019.25));

        //Print the statement

        System.out.println("Testing the basic rate again, should still be 7.5%.");

        //Print the statement

        System.out.println(" Item price no tax: 210.99");

        //Print the statement

        System.out.println("cost with 7.5% tax: "+ TaxComputer.computeCostBasic(210.99));

    }

}

Sample Output

Output:

Testing the basic rate computation.

 Item price no tax: 10.00

cost with 4% tax: 10.4

Testing the basic rate computation.

 Item price no tax: 10.00

cost with 7.5% tax: 10.75

Testing the luxury rate computation.

 Item price no tax: 2019.25

cost with 10% tax: 2221.18

Testing the luxury rate computation.

 Item price no tax: 2019.25

cost with 20% tax: 2423.1

Testing the basic rate again, should still be 7.5%.

 Item price no tax: 210.99

cost with 7.5% tax: 226.81

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
1. Level the resources (R) for the following network. Show exactly which activity is being moved at each cycle and how many days it is being moved. Show all cycles required to utilize the free float and the back float. B H 3 3 L 2 0-0-0 A C F G K N P Q T 0 3 2 2 1 2-2-2 7R 8R 4R 6R 4R 2R 5R 4R D 1 2R 2 M 000 4R 2 4R 1 2 3 4 B5 B BE B 5 5 7 D 2003 C NO C MBSCM В H 5 2 F 7 7 8 SH2F80 5 Н Н 6 7 7L3G4+ 6H2G4 J 4 4 14 8 L K 00 36 9 10 11 12 13 14 15 P 2 Z+ N N 4 4 Z t 2334 4 Σ + M M 4 +
2. Perform resource allocation for the following project. Resource limits are 6 labors and 2 helpers. Legend: Activity Dur Resources G H 2 3 2L 1H 2L OH A 1 3L 1H + B D F J K 3 4 6 2 4 4L 2H 3L OH 4L 1H 2L 2H 4L 2H C E 2 2 I 1 2L 1H 3L 1H 5L 1H
Need Java method please. Thank you.

Chapter 6 Solutions

Java: An Introduction to Problem Solving and Programming (7th Edition)

Chapter 6.2, Problem 11STQChapter 6.2, Problem 12STQChapter 6.2, Problem 13STQChapter 6.2, Problem 14STQChapter 6.2, Problem 15STQChapter 6.2, Problem 16STQChapter 6.2, Problem 17STQChapter 6.2, Problem 18STQChapter 6.2, Problem 19STQChapter 6.2, Problem 20STQChapter 6.2, Problem 21STQChapter 6.2, Problem 22STQChapter 6.2, Problem 23STQChapter 6.2, Problem 24STQChapter 6.2, Problem 25STQChapter 6.2, Problem 26STQChapter 6.3, Problem 27STQChapter 6.3, Problem 28STQChapter 6.3, Problem 29STQChapter 6.3, Problem 30STQChapter 6.3, Problem 31STQChapter 6.4, Problem 32STQChapter 6.4, Problem 33STQChapter 6.4, Problem 34STQChapter 6.4, Problem 35STQChapter 6.4, Problem 36STQChapter 6.4, Problem 37STQChapter 6.4, Problem 38STQChapter 6.4, Problem 39STQChapter 6.5, Problem 40STQChapter 6.6, Problem 41STQChapter 6.7, Problem 42STQChapter 6.7, Problem 43STQChapter 6.7, Problem 44STQChapter 6.7, Problem 45STQChapter 6.8, Problem 46STQChapter 6.8, Problem 47STQChapter 6.8, Problem 48STQChapter 6.8, Problem 49STQChapter 6.8, Problem 50STQChapter 6.8, Problem 51STQChapter 6.8, Problem 52STQChapter 6, Problem 1EChapter 6, Problem 2EChapter 6, Problem 3EChapter 6, Problem 4EChapter 6, Problem 5EChapter 6, Problem 6EChapter 6, Problem 7EChapter 6, Problem 8EChapter 6, Problem 9EChapter 6, Problem 10EChapter 6, Problem 11EChapter 6, Problem 12EChapter 6, Problem 1PChapter 6, Problem 2PChapter 6, Problem 3PChapter 6, Problem 4PChapter 6, Problem 5PChapter 6, Problem 6PChapter 6, Problem 7PChapter 6, Problem 1PPChapter 6, Problem 2PPChapter 6, Problem 3PPChapter 6, Problem 4PPChapter 6, Problem 5PPChapter 6, Problem 6PPChapter 6, Problem 7PPChapter 6, Problem 8PPChapter 6, Problem 9PPChapter 6, Problem 10PPChapter 6, Problem 11PPChapter 6, Problem 12PPChapter 6, Problem 13PPChapter 6, Problem 14PPChapter 6, Problem 15PP
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning