Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4: You are now going to create a class on your own that calculates the sales tax on a purchase and return the total

Problem 4: You are now going to create a class on your own that calculates the sales tax on a purchase and return the total price of the purchase. (This should be similar to the BankAccount class).

  1. Create a class named SalesTax.

  2. You will need two instance variables totalCost and taxRate. Each should be a double.

  3. Create a constructor that initializes the instance variable, totalCost and tax. The constructor should be patterned after BankAccount with a default constructor and the totalCost set to 0 and the taxRate to a default of .05.

  4. Create another constructor with one argument in the parameter. The argument will hold the tax. Set the taxRate to tax and the totalCost to 0.

  5. Create a method called calculateTotal. (This method should be similar to Deposit) with no return value.

    1. This method should accept as input the price of the purchase (a parameter variable called purchase)

    2. Calculate the totalCost. (Think about the formula you will need to do this.) You will need to set totalCost = the formula you determine. You will return this totalCost in another method. Remember you should not return a value in a mutator method.

  1. There should be a method getTotalCost.

  1. This method has only one purpose and that is to return the totalCost. It returns a double. (See getBalance from BankAccount)

  2. Write a SalesTaxTester class. This will be very similar to the BankAccountTester on page 101 of your text. It will have a main.

    1. Create an object of type SalesTax using the default constructor.

    2. Call the calculateTotal method. Use a purchase price of $50.

    3. Print the results.

    4. Create an object of type SalesTax and provide an argument of .08.

    5. Call the calculateTotal method with a purchase price of $100.

    6. Print the results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions

Question

=+2. In what ways might this commitment prove disadvantageous?

Answered: 1 week ago

Question

3. How has e-commerce transformed marketing?

Answered: 1 week ago