In: Computer Science
Create a Java project called (clsCashRegister.java)
The context of this project is a cash register at a shop. The cash register should display a list of items for sale with the price for each item. The cash register should calculate the total cost of the user’s purchase, receive a payment from the user, add tax to the cost, deduct the cost from the payment, and return the exchange back to the user.
Display a welcome message: “Welcome to Cash Mart”
Display a message to the users with the options below. Create a method called ViewOptions() to display the options below. This method doesn’t accept any parameters and does not return anything. This method should be called right after you display the message in Step 1, and after all options below accomplish their deliverable:
a. Type “view” to view items and prices.
b. Type “purchase” to make a purchase.
c. Type “delete” to remove items from the cart. [optional#2].
d. Type “cart” to view currents item in the cart [optional#3].
e. Type “pay” to make a payment
f. Type “exit” to terminate the program
if the user types anything else, then display an error message “invalid option”.
If the user types “view”, call a method called View Items(), which accepts no parameters and returns nothing. The method should display the following:
*****************We have the following items******************
b. If the user types “purchase”, display each item with its price and ask the user to input the number of each item. Once all items are purchased, call the method in Step 4. Your message should look like the message below. Repeat this for all items in the list with your own quantities:
Enter number of pounds of Bananas @ $1.5/ pound: 5 You entered 5 pounds of Bananas, hit y to confirm, n to re-enter bananas. Enter the number of pounds of Apples @ $2.5 / pound: 100 You entered 100 pounds of apples, hit y to confirm, n to re-enter ………. [repeat for all items]
Once all items are displayed, and items are chosen purchase, call a method called CalculatePurchase(dblBanana, dblApple, intPizza, intPop, intCoffee) which accepts 6 parameters as doubles and integers [refer to the names in the method] , each representing the number of items purchased, and then returns the total cost of the purchase in USD. This method should be called after a purchase is made; it should also add a tax sale of 8.1% on all purchases made. Once this method is called, display a summary of purchases including the number of items, items’ names, price per item, total of each item, the number of total categories purchased, the sales tax, and the total amount due to pay. The item category is the number of non-zero items purchases. In this case, its apples, pizza, and pop which is 3.
The following items are purchased:
No. Items | Item name and cost | Total($) --------------------------------------------------------------------------------------
0 |Bananas |0.00
3 |Apples |7.50
1 |Pizza |9.99
4 |Pop |7.96
0 |Coffee |0.00
No. categories 3 $25.45
Sales Tax (8.1%) $2.06
Total $ 27.51
Please, type “pay” to make a payment.
Once “pay” is typed, call a method called Pay(dblCost, dblPayment) which accepts two double values, the cost of the purchase returned from the CalculatePurchase() method, and the payment provided from the user. This method should return the exchange for the user in USD. If the payment is less than the cost, ask the user to insert the payment again. You can accept the payment when you call the Pay method. When this method is called, pass the cost and the mount 0 as payment, then calculate the change. Then display a message with the transaction, something like this:
>>pay
Your total purchase is $27.1, please enter payment in USD:
>> 5
You still owe $22.1, please enter payment again in USD:
>> 30
Your change is $7.9.
Create a method called ExchangeReturn(dblExchange) to calculate the number of bill and coins to be returned. SAMPLE USER EXPERIENCE The following is an example of what the user should experience. Try to make you program to look like the below user experience. Highlighted text indicates an input from the user and italic text indicates the output of your program. Reasonable modifications are acceptable. ========================================
Welcome to Cash Mart, please choose one of the options below: Type “view” to view items and prices. Type “purchase” to make a purchase. Type “delete to remove items from the cart. (optional). Type “cart” to view currents item in the cart (optional). Type “pay” to make a payment >> hello Invalid input, please choose a valid input Welcome to Cash Mart, please choose one of the options below: Type “view” to view items and prices. Type “purchase” to make a purchase. Type “delete to remove items from the cart. (optional). Type “cart” to view currents item in the cart (optional). Type “pay” to make a payment
>> DELETE
Nothing to delete. Cart is empty.
>> Cart is empty
>>View
*****************We have the following items******************
Bananas ----------------------- $1.50 / pound
Apples ----------------------- $2.50 / pound
Pizza ----------------------- $9.99 / large pizza
Pop ----------------------- $1.99 / bottle
Coffee ----------------------- $1.59 / cup
Enter the number of items you’d like to purchase:
No. of Bananas at 1.50/pound
>>0 No. of apples at 2.50/pound
>>3 No. of large pizza
>>1 No. of pop bottles
>>2 No. of cups of coffee
>>0
The following items are purchased No. Items | Item name |
Total ($) ----------------------------------------------
0 |Bananas | 0.00
3 |Apples | 7.50
1 |Pizza | 9.99
2 |Pop | 3.98
0 |Coffee | 0.00
No. Items 6 $21.47
Sales Tax (8.1%) $1.73
Total $23.20
Welcome to Cash Mart, please choose one of the options below:
Type “view” to view items and prices.
Type “purchase” to make a purchase.
Type “delete to remove items from the cart. (optional).
Type “cart” to view currents item in the cart (optional).
Type “pay” to make a payment
>>PAY
Your total purchase is $23.20, please enter payment in USD:
>> 5
You still owe $18.20, please enter payment again in USD:
>> 30 Your change is $11.80.
>>exit
Thank you, come again.
import java.util.Scanner;
public class clsCashRegister {
/*
* Creating an Scanner class object which is used to get the inputs
entered
* by the user
*/
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int bananas = 0, apples = 0, pizza = 0, coffee = 0, pop = 0;
DisplayInfo();
while (true) {
ViewOptions();
System.out.print("Enter Choice :");
String choice = sc.next();
if (choice.equalsIgnoreCase("view")) {
ViewItems();
continue;
} else if (choice.equalsIgnoreCase("purchase")) {
int num;
char ch;
System.out.print("Enter Choice :");
num = sc.nextInt();
switch (num) {
case 1: {
while (true) {
System.out
.print("Enter number of pounds of Bananas @1.15/pound:");
num = sc.nextInt();
System.out
.print("You entered "
+ num
+ " pounds of Bananas, hit y to confirm, n to re-enter
bananas.");
ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
break;
}
}
bananas += num;
break;
}
case 2: {
while (true) {
System.out
.print("Enter number of pounds of Apples @2.5/pound:");
num = sc.nextInt();
System.out
.print("You entered "
+ num
+ " pounds of Apples, hit y to confirm, n to re-enter
Apples.");
ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
break;
}
}
apples += num;
break;
}
case 3: {
while (true) {
System.out.print("Enter number of pizzas @9.90/pizza:");
num = sc.nextInt();
System.out
.print("You entered "
+ num
+ " nos of Pizzas, hit y to confirm, n to re-enter Pizzas.");
ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
break;
}
}
pizza += num;
break;
}
case 4: {
while (true) {
System.out.print("Enter number of pops @1.99/pop:");
num = sc.nextInt();
System.out
.print("You entered "
+ num
+ " nos of Pops, hit y to confirm, n to re-enter Pop.");
ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
break;
}
}
pizza += num;
break;
}
case 5: {
while (true) {
System.out.print("Enter number of Coffee @1.59/pop:");
num = sc.nextInt();
System.out
.print("You entered "
+ num
+ " nos of Coffee, hit y to confirm, n to re-enter Coffee.");
ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y') {
break;
}
}
coffee += num;
break;
}
default: {
System.out.println("** Inavlid Choice **");
break;
}
}
break;
} else if (choice.equalsIgnoreCase("delete")) {
break;
} else if (choice.equalsIgnoreCase("cart")) {
break;
} else if (choice.equalsIgnoreCase("pay")) {
break;
} else if (choice.equalsIgnoreCase("exit")) {
break;
} else {
System.out.println("** Invalid Choice **");
}
}
}
private static void ViewItems() {
System.out
.println("==================We have the following
Items===================");
System.out.println("1.Bananas
---------------------$1.50/pound");
System.out.println("2.Apples
----------------------$2.50/pound");
System.out.println("3.Pizza
-----------------------$9.99/pound");
System.out.println("4.Pop
-------------------------$1.99/pound");
System.out.println("5.Coffee
----------------------$1.59/pound");
}
private static void ViewOptions() {
System.out.println("view");
System.out.println("purchase");
System.out.println("delete");
System.out.println("cart");
System.out.println("pay");
System.out.println("exit");
}
private static void DisplayInfo() {
System.out.println("============================================");
System.out.println("Welcome to cash Mart");
System.out.println("Your lastname , firstname");
System.out.println("Your e-mail address");
System.out.println("CS110-001, Spring 2020");
System.out.println("Project No.1ash Register");
System.out.println("============================================");
}
}