Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Create a new class that calculates the sales tax on a purchase. (This should be similar to the BankAccount class). a. Create a
2. Create a new class that calculates the sales tax on a purchase. (This should be similar to the BankAccount class). a. Create a class named SalesTax. b. You will need 4 instance variables: tax, purchasePrice, taxDue, and totalCost. The variable tax will hold the sales tax rate (as a percent value); purchasePrice will hold the price of the item purchased; taxDue wil hold the amount of tax for the purchased item calculated based on the sales tax rate, and totalCost will hold the purchase price plus the tax due. Think about what kind of data each variable will hold to determine what type the variables should be. c. Create 2 constructors. The constructors should be patterned after BankAccount with a default constructor with the tax set to 0 and another constructor that sets the tax equal to the explicit parameter (argument). d. Create a method called calculateSalesTax. (This method should also be similar to deposit in the Bankaccount class). i. This method should accept as input the price of the purchase (a parameter variable called purchase). ii. Use an assignment statement in the body of the method to update the instance variable purchasePrice with the price in the explicit parameter of this method. i. Use the tax rate and the purchase price to calculate the value for the tax due and update the taxDue instance variable. This method will only calculate and store the tax, it will not return anything. e. Create a method called totalCost. This method will not accept any input (no arguments) and will not return anything. i. This method will calculate the total cost by adding the purchase price to the tax due and updating the totalCost instance variable. ii. The method will not return anything. f. Create a method getTotalCost. i.This method has only one purpose and that is to return the totalCost. ii.(Similar to the getBalance method from BankAccount) g. Write a tester class for the SalesTax class. This will be very similar to the BankAccountTester on page 103 of your text. It will have a main ii. Create an object of type SalesTax with an initial sales tax of 10%. iii. Call the calculateSalesTax method. iv. Call the totalCost method. V. Call the getTotalCost method and assign it to a variable called cost. vi. Print the cost.
Step by Step Solution
★★★★★
3.48 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
SalesTaxjava package sandboxtax class SalesTax instance variables private double tax private double ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started