Question

In: Computer Science

Create a Java project called (clsCashRegister.java) The context of this project is a cash register at...

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

  1. Bananas--------------------------------- $1.50 / pound
  2. Apples ---------------------------------- $2.50/ pound
  3. Pizza ------------------------------------- $9.99 / large pizza
  4. Pop--------------------------------------- $1.99 / bottle
  5. Coffee ----------------------------------- $ 1.59 / cup

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.

Solutions

Expert Solution

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("============================================");

}

}

  


Related Solutions

In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package...
In STS, create Java Project, called java_generics_yourNameLastname that; (Under source directory called, src, create a package csci3444.generics and put all code in it) Create a generic interface called “MyGenInterface” that takes 2 generic types K,V with below methods; public K getKey(); public V getValue(); Create a generic class called “MyGenClass” that implements “MyGenInterface” interface. has attributes “K key” and “V value” that can be inherited has a constructor that takes “K _key”, “V _value” inputs and initializes “key”, “value” attributes...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT