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
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.

Expert Solution & Answer
Check Mark
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
Why is Linux popular? What would make someone choose a Linux OS over others? What makes a server? How is a server different from a workstation? What considerations do you have to keep in mind when choosing between physical, hybrid, or virtual server and what are the reasons to choose a virtual installation over the other options?
Objective  you will: 1. Implement a Binary Search Tree (BST) from scratch, including the Big Five (Rule of Five)  2. Implement the TreeSort algorithm using a in-order traversal to store sorted elements in a vector. 3. Compare the performance of TreeSort with C++'s std::sort on large datasets. Part 1: Understanding TreeSort How TreeSort Works TreeSort is a comparison-based sorting algorithm that leverages a Binary Search Tree (BST): 1. Insert all elements into a BST (logically sorting them). 2. Traverse the BST in-order to extract elements in sorted order. 3. Store the sorted elements in a vector.  Time Complexity Operation                                Average Case     Worst Case (Unbalanced Tree)Insertion                                     0(1log n)                0 (n)Traversal (Pre-order)                  0(n)                       0 (n)Overall Complexity                  0(n log n)                 0(n^2) (degenerated tree) Note: To improve performance, you could use a…
I need help fixing the minor issue where the text isn't in the proper place, and to ensure that the frequency cutoff is at the right place. My code: % Define frequency range for the plot f = logspace(1, 5, 500); % Frequency range from 10 Hz to 100 kHz w = 2 * pi * f; % Angular frequency   % Parameters for the filters - let's adjust these to get more reasonable cutoffs R = 1e3; % Resistance in ohms (1 kΩ) C = 1e-6; % Capacitance in farads (1 μF)   % For bandpass, we need appropriate L value for desired cutoffs L = 0.1; % Inductance in henries - adjusted for better bandpass response   % Calculate cutoff frequencies first to verify they're in desired range f_cutoff_RC = 1 / (2 * pi * R * C); f_resonance = 1 / (2 * pi * sqrt(L * C)); Q_factor = (1/R) * sqrt(L/C); f_lower_cutoff = f_resonance / (sqrt(1 + 1/(4*Q_factor^2)) + 1/(2*Q_factor)); f_upper_cutoff = f_resonance / (sqrt(1 + 1/(4*Q_factor^2)) - 1/(2*Q_factor));   % Transfer functions % Low-pass filter (RC) H_low = 1 ./ (1 + 1i * w *…

Chapter 6 Solutions

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

Ch. 6.2 - Can you reference an instance variable by name...Ch. 6.2 - Is the following valid, given the class...Ch. 6.2 - Prob. 13STQCh. 6.2 - Prob. 14STQCh. 6.2 - Prob. 15STQCh. 6.2 - Is the following valid, given the class...Ch. 6.2 - What values are returned by each of the following?...Ch. 6.2 - Suppose that speed is a variable of type double...Ch. 6.2 - Repeat the previous question, but instead assign...Ch. 6.2 - Suppose that nl is of type int and n2 is of type...Ch. 6.2 - Define a class CircleCalculator that hat only two...Ch. 6.2 - Which of the following statements are legal?...Ch. 6.2 - Write a Java expression to convert the number in...Ch. 6.2 - Consider the variable 5 of type String that...Ch. 6.2 - Repeat the previous question, but accommodate a...Ch. 6.2 - Write Java code to display the largest and...Ch. 6.3 - Prob. 27STQCh. 6.3 - Consider the variable allCents in the method...Ch. 6.3 - What is wrong with a program that starts as...Ch. 6.3 - Prob. 30STQCh. 6.3 - In your definition of the class OutputFormat. In...Ch. 6.4 - Prob. 32STQCh. 6.4 - Prob. 33STQCh. 6.4 - Prob. 34STQCh. 6.4 - Consider the class Species in Listing 5.19 of...Ch. 6.4 - Repeat the previous question for a method...Ch. 6.4 - Still considering the class Species in Listing...Ch. 6.4 - Rewrite the method add in Listing 6.16 so that it...Ch. 6.4 - In Listing 6.16, the set method that has a String...Ch. 6.5 - Give the definitions of three accessor methods...Ch. 6.6 - If cardSuit is an instance of Suit and is assigned...Ch. 6.7 - Suppose you want to use classes in the package...Ch. 6.7 - Prob. 43STQCh. 6.7 - Can a package have any name you might want, or are...Ch. 6.7 - On your system, place the class Pet (Listing 6.1)...Ch. 6.8 - Prob. 46STQCh. 6.8 - Prob. 47STQCh. 6.8 - Prob. 48STQCh. 6.8 - Prob. 49STQCh. 6.8 - Prob. 50STQCh. 6.8 - Prob. 51STQCh. 6.8 - Revise the applet in Listing 6.24 so that the...Ch. 6 - Prob. 1ECh. 6 - Prob. 2ECh. 6 - Write a default constructor and a second...Ch. 6 - Write a constructor for the class...Ch. 6 - Consider a class characteristic that will be used...Ch. 6 - Create a class RoomOccupancy that can be used to...Ch. 6 - Write a program that tests the class RoomOccupancy...Ch. 6 - Sometimes we would like a class that has just a...Ch. 6 - Create a program that tests the class Merlin...Ch. 6 - In the previous chapter, Self-Test Question 16...Ch. 6 - Create a class Android whose objects have unique...Ch. 6 - Prob. 12ECh. 6 - Modify the definition of the class Species in...Ch. 6 - Prob. 2PCh. 6 - Using the class Pet from Listing 6.1, write a...Ch. 6 - Do Practice Program 4 from Chapter 5 except define...Ch. 6 - The following class displays a disclaimer every...Ch. 6 - Do Practice Program 5 from Chapter 5 but add a...Ch. 6 - We can improve the Beer class from the previous...Ch. 6 - Define a utility class for displaying values of...Ch. 6 - Write a new class TruncatedDollarFormat that is...Ch. 6 - Complete and fully test the class Time that...Ch. 6 - Complete and fully test the class Characteristic...Ch. 6 - Write a Java enumeration LetterGrade that...Ch. 6 - Complete and fully test the class Per n that...Ch. 6 - Write a Temperature class that represents...Ch. 6 - Repeat Programming Project 8 of the previous...Ch. 6 - Write and fully test a class that represents...Ch. 6 - Write a program that will record the votes for one...Ch. 6 - Repeat Programming Project 10 from Chapter 5, but...Ch. 6 - Prob. 12PPCh. 6 - Prob. 13PPCh. 6 - Prob. 14PPCh. 6 - Prob. 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