Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I have a programming assignment that is a continuation to the original java assignment for Cash Register which is as follows: class CashRegister{ int item;

I have a programming assignment that is a continuation to the original java assignment for Cash Register which is as follows:

class CashRegister{ int item; float itemCost; float total; // Constructor takes an argument itemNumber CashRegister(int item) { this.item = item; setCost(item); } // Setter and Getter methods public int getItem() { return item; } public float getItemCost() { return itemCost; } public void setItemCost(float itemCost) { this.itemCost = itemCost; } public float getTotal() { return total; } public void setTotal(float total) { this.total = total; } // Sets the cost of items void setCost(int number) { if(number == 1) { setItemCost(10); } else if(number == 2) { setItemCost(20); } else if(number == 3){ setItemCost(30); } } // Computes the total due by adding a 10% tax to the original cost void computeTotal() { setTotal(((getItemCost()*10)/100) + getItemCost()); } // Computes the change void displayTransaction(float amount) { float change = amount - getTotal(); System.out.println("You have selected item number: " + getItem()); System.out.println("The cost of this item is: " + getItemCost()); System.out.println("Your total with tax is: " + getTotal()); System.out.println("You have paid: " + amount); System.out.println("Your change is: "+ change); } // Passes the paid amount to displayTransaction method void pay(float amount) { this.displayTransaction(amount); } }

*****************************************************************************************************************************************************

For my assignment that I need help with inow s that I have to modify assignment two, Cash Register, taking into consideration the following changes: This will be an interactive program. It will start by asking you how many items you have on your list, then the program will loop that many times, during each loop iteration it will ask for the items name, price and whether it is to be taxed or not. Note that each item has a name, price, and identified as a taxable or nontaxable item. After all the items are registered, the program will display a rescript including each items name and its price along with the total due at the end of the receipt. The program will present you with the total amount due again and asks you to enter amount paid. If the payment is equal to or more than the total amount due it will print a thank you message and dispense the change, otherwise it will ask you for the remainder of the payment due. A sample output for two scenarios are shown below, note that the users input is not case sensitive, its shown in bold text. You are required to create at least three classes for this assignment, however, you may create more. I have to submit a zipped file for all of the classes used to solve this assignment. First run ****************************************************************** How many items on your list? 3 Name your next item: Meat How much was it: 10.00 Is it a taxable (Yes/No): no Name your next item: Pots How much was it: 20 Is it a taxable (Yes/No): Yes Name your next item: Pepper How much was it: 5 Is it a taxable (Yes/No): No Your Receipt: Meat $10.0 Pots $20.0 Pepper $5.0 Your Total Is: 37.0 ****** Your total is: 37.0 Please insert payment: 40 Thank you for shopping with us Don't forget your change of: 3.0 Second run ***************************************************************** How many items on your list? 3 Name your next item: Meat How much was it: 10.00 Is it a taxable (Yes/No): no Name your next item: Pots How much was it: 20 Is it a taxable (Yes/No): Yes Name your next item: Pepper How much was it: 5 Is it a taxable (Yes/No): no Your Receipt: Meat $10.0 Pots $20.0 Pepper $5.0 Your Total Is: 37.0 ****** Your total is: $37.0 Insert Money: 20 Thank you for shopping with us You still owe $17.00 Bonus: Your program must accept only valid inputs. For example if the user enters a string when the program expect an integer it must reject the input and allow the user another try. Here is a sample run: How many items on your list? Meat How many items on your list, Integer values ONLY? Potatoes How many items on your list, Integer values ONLY? 1 Name your next item: Meat . . . Hints: Make sure you clear the buffer when interacting with the program after some readings. You will see this when the program does not allow you to enter certain inputs and skips to the next. Here is a snippet of code that checks for integer inputs, note the second to last line that clears the buffer: while (!done) { if (input.hasNextInt()) { num = input.nextInt(); done = true; } else { g = input.nextLine();//clearing the buffer System.out.print("How many.., Integer values ONLY? "); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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