Question: Hi! I am in need of help with a Java programming assignment. I have the java program completed for the cash register (see very end),

Hi! I am in need of help with a Java programming assignment. I have the java program completed for the cash register (see very end), but it needs to be modified to spit out the scenario below (BOLD is what the user inputs).It should 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 item name, price, taxable (y/n) then spit out the receipt with breakdown in the example below.

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

--> After it asks the questions above, it needs to print the below information

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

or, if enough money was not given, then it will ask for the remainder.

Your total is: $37.0

Insert Money: 20

Thank you for shopping with us

You still owe $17.00

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

Here is the Java program I wrote that needs to be modified for the above needs:

import java.util.Scanner;

public class CashRegister

{

private int itemNumber = 0;

private double cost = 0;

private double total = 0;

private double payment = 0;

private double change = 0;

private void setItemNumber(int item){

this.itemNumber = item;

}

private int getItemNumber(){

return this.itemNumber;

}

private void setTotal(double t){

this.total = t;

}

private double getTotal(){

return this.total;

}

private void setPayment(double pay){

this.payment = pay;

}

private double getPayment(){

return this.payment;

}

private void setChange(double ch){

this.change = ch;

}

private double getChange(){

return this.change;

}

private void setCost(){

int item = getItemNumber();

if (item == 1){

this.cost = 10;

}

else if (item == 2){

this.cost = 20;

}

else if (item == 3){

this.cost = 30;

}

}

private double getCost(){

return this.cost;

}

public CashRegister(int item){

setItemNumber(item);

setCost();

}

public void computTotal(){

double tot = getCost() * 1.10;

setTotal(tot);

}

public void pay(double p){

setPayment(p);

double c = p - getTotal();

setChange(c);

}

public void displayTransaction(){

System.out.println("You have selected item number: " + getItemNumber());

System.out.println("The cost of this item is: " + getCost());

System.out.println("Your total with tax is: " + getTotal());

System.out.println("You have paid: " + getPayment());

System.out.println("Your change is: " + getChange());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!