Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I am writing a Java program that is supposed to calculate the prices of store items on certain tax rates. I figured out how

Hi, I am writing a Java program that is supposed to calculate the prices of store items on certain tax rates. I figured out how to output the prices to the screen, however I am unsure how to code it so that it applies to the tax rate to the certain items. The code can be found below. Thanks in advance.

Instructions

1) Add a method changeTax() that changes the current tax rate by the amount in the parameter 2) Add a main method 3) In the main, create two instances of TaxWhiz with a tax rates of 8.75 and 4.75 percent 4) Compute the tax on two different purchases (one at the * 8.75 and one at the 4.75 rates 5) Print the total of two purchases, the total tax and the total amount (purchases+tax) (try to make it look like a store receipt as best as you can, this actually could take trial/error) 6) Repeat steps 4) and 5) but first increment the tax rate by 1.0 percentage point
 import java.util.Date; public class TaxWhiz { private double taxRate; /** * TaxWhiz() constructor creates an object with * a given tax rate * @param t -- the given tax rate */ public TaxWhiz(double t) { taxRate = t; } /** * calcTax() returns the tax for a given purchase * @param purchase -- the given purchase price */ public double calcTax(double purchase) { return taxRate * purchase; } /** * changeTax() changes the current tax * @param t -- the change added to the current tax rate */ public void changeTax(double t) { } public static void main(String[] args) { TaxWhiz first = new TaxWhiz(8.75); TaxWhiz second = new TaxWhiz(4.75); double itemOne, itemTwo, itemTax; itemOne = 20.00; itemTwo = 30.00; itemTax = first.calcTax(itemOne) + first.calcTax(itemTwo); System.out.println(" Welcome To Tom's Sports Shop "); System.out.println(new Date() + " "); System.out.println("Recipt for tax rate of 8.75%: "); first.makeReceipt(itemOne, itemTwo,itemTax); itemTax = second.calcTax(itemOne) + second.calcTax(itemTwo); System.out.println(" Recipt for tax rate of 4.75%: "); second.makeReceipt(itemOne, itemTwo, itemTax); first.changeTax(1); second.changeTax(1); itemTax = first.calcTax(itemOne) + first.calcTax(itemTwo); System.out.println("Recipt for tax rate of 9.75%: "); first.makeReceipt(itemOne,itemTwo, itemTax); itemTax = second.calcTax(itemOne) + second.calcTax(itemTwo); System.out.println("Receipt for tax rate of 5.75%: "); second.makeReceipt(itemOne, itemTwo, itemTax); } public void makeReceipt(double firstItem, double secondItem, double tax) { System.out.println("-------------------------------------"); System.out.println("------------Sales Receipt-------------"); System.out.println("--"); System.out.println(" Item 1 : $" + String.format("%.2f",firstItem)); System.out.println(" Item 2 : $" + String.format("%.2f",secondItem)); System.out.println(" Total : $" + String.format("%.2f",(firstItem + secondItem))); System.out.println("--"); System.out.println(" Final Price : $" + String.format("%.2f",(firstItem + secondItem))); System.out.println("--"); System.out.println("--------Thank You For Shopping With US-------------"); System.out.println("--------------------------------------"); System.out.println("--"); } } // end TaxWhiz class image text in transcribedimage text in transcribed
10 import java.util.Date; 11 public class TaxWhiz { 12 private double taxRate; 13 14 15e /** 16 * TaxWhiz() constructor creates an object with 17 18 * @param t -- the given tax rate 19 20 21 22 public TaxlWhiz(double t) { 23 24 25e /*x 26 * calcTax() returns the tax for a given purchase 27 * @param purchase -the given purchase price 28 29e public double calcTax(double purchase) 30 *a given tax rate taxRate = t; return taxRate * purchase; 32 ** 33 * changeTax) changes the current tax 34 * @param t -- the change added to the current tax rate 35 * 36 public void changeTax (double t) 37 39 public static void main(String[l args) 40 TaxWhiz first -new TaxWhiz(8.75); TaxWhiz second = new TaxWh 12(4.75); double itemOne, itemTwo, itemTax; item0ne 20.00; itemTwo 30.00; itemTax first . calcTax(itenOne) + first . calcTax(itemTwo); System.out.println(" Welcome To Tom's Sports Shop "); System.out.println(new Date)" "); System.out.printIn("Recipt for tax rate of 8.75%: "); first.makeReceipt (itemOne, itemTwo,itemTax); itemTax second . calcTax(itenOne) + second . calcTax(itemTwo); System.out.printIn(" Recipt for tax rate of 4.75%; "); 42 45 46 47 48 49 50 51 Taxhhiz first new Taxhhiz(8.75); Taxhhiz second = new TaxWh 12(4.75); double itemOne, itemTwo, itemTax; itemOne20.00 itemTwo30.00 itemTax first . calcTax(itenOne) + first . calcTax(itemTwo); System.out.println(" Welcome To Tom's Sports Shop "); System.out.println (new Date()" "); System.out.println("Recipt for tax rate of 8.75% "); first.makeReceipt (itemOne, itemTwo,itemTax); itemTax second . calcTax(itenOne) + second . calcTax(itemTwo); System.out.println(" Recipt for tax rate of 4.75%; "); second.makeReceipt(itemOne, itemTwo, itemTax); first.changeTax(1); second.changeTax(1); itemTax first . calcTax(itenOne) + first . calcTax(itemTwo); System.out.println("Recipt for tax rate of 9.75% "); first.makeReceipt (itemOne,itemTwo, itemTax); itemTax second . calcTax(itenOne) + second . calcTax(itemTwo); System.out.printIn("Receipt for tax rate of 5.75% "); second.makeReceipt(itemOne, itemTwo, itemTax); 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 62 636 64 65 public void makeReceipt (double firstItem, double secondItem, double tax) { 67 68 69 70 71 72 73 74 75 76 System.out.println(--- System.out.println("Sales Receipt--- System.out.println("-"); System . out . print In(" Item 1 : $" + String.format(".2f",first!ten) ); System . out . print In(" Item 2 : $" + String.format(".2f",seconditen)); System.out . printin (" Total : $" + String.format(".2f", (firstItem + secondlten))); System.out.println("-"); System . out . printin (" Final Price : $" + String.format(".2f", (firstItem + secondlten))); System.out.println("-"); System.out.println(" System.out.println(" System.out.println("-"); Thank You For Shopping With US- 78 79 80 81 82 I end TaxWhiz class

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

Do both large and small projects require governance? Why?

Answered: 1 week ago

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago