Requirements description: Assume you work part-time at a sandwich store. As the
ID: 3844039 • Letter: R
Question
Requirements description:
Assume you work part-time at a sandwich store. As the only employee who knows java programming, you help to write a sandwich ordering application for the store. The following is a brief requirement description with some sample output.
1. Selecting bread:
When the program starts, it first shows a list/menu of sandwich breads and their prices, then asks a user to select a bread by entering an integer number. A sample output is as follows
=== Select Sandwich Bread: ===
1 White Bread $1.5
2 Wheat Bread $1.8
3 French Bread $2.0
4 Organic Bread $2.3
Select a bread [1, 4]:
In your program, you can hard-code the information for sandwich breads (i.e., bread names and prices) shown above, such as “1 White Bread $1.5” and use the hard-code price, such as 1.5, for calculation of a total price of the order.
2. Selecting vegetables
After the user provides a right bread number for bread selection, the program asks the user to select vegetables. A sample output is as follows.
=== Select Sandwich Vegetables: ===
1 red onions $0.10
2 olives $0.10
3 pickles $0.10
4 lettuce $0.20
5 green peppers $0.25
6 tomatoes $0.30
7 cheese $0.49
8 Quit vegetable selection
Select vegetables: [1, 8]:
You hard-code the vegetables information as shown above, such as “ 1 red onions $0.10” and use the hard-code price, such as 0.10, for calculation of the total price of the order.
After the user makes a choice for vegetable, such as 2 for olives. The program continues asking for selecting a vegetable so that the user can have multiple vegetables for one sandwich. The user can enter “8” to quit vegetable selection. A sample output is as follows.
=== Select Sandwich Vegetables: ===
1 red onions $0.10
2 olives $0.10
3 pickles $0.10
4 lettuce $0.20
5 green peppers $0.25
6 tomatoes $0.30
7 cheese $0.49
8 Quit vegetable selection
Select vegetables: [1, 8]: 2
=== Select Sandwich Vegetables: ===
1 red onions $0.10
2 olives $0.10
3 pickles $0.10
4 lettuce $0.20
3. Selecting meat
After vegetable selection, the program shows meat selection. A sample output is as follows.
=== Select Sandwich Vegetables: ===
1 red onions $0.10
2 olives $0.10
3 pickles $0.10
4 lettuce $0.20
5 green peppers $0.25
6 tomatoes $0.30
7 cheese $0.49
8 Quit vegetable selection
Select vegetables: [1, 8]: 8
=== Select Sandwich Meat: ===
1 Ham $0.9
2 Roasted Chicken Breast $1.0
3 Turkey Breast $1.1
4 Roast Beef $1.5
5 Quit meat selection
Select meat [1, 5]:
Input validation is needed and works as before. Unlike vegetable selection which allows selecting multiple vegetables, meat selection does not repeat after the user enters a valid number between 1 and 5.
You hard-code the information for meat shown above, such as “1 Ham $0.9” and use the hard-code price, such as 0.9, for calculation of the total price of the order.
4. Entering a customer’s name
After making a meat selection, the program asks for the user’s name so that the user can enter text like John or John Smith.
=== Select Sandwich Meat: ===
1 Ham $0.9
2 Roasted Chicken Breast $1.0
3 Turkey Breast $1.1
4 Roast Beef $1.5
5 Quit meat selection
5. Displaying and writing order line information
After entering a name, the program prints details for this order line in computer monitor. The information includes the six fields: date and time, customer name, bread, vegetable(s), meat, and a (formatted) total price, and each field is separated by a tab, /t. A sample output to the monitor is as follows.
Enter customer's name: John Smith
Jul 6, 2016 10:35:43 AM John Smith
Organic Bread lettuce, tomatoes, green peppers Roast Beef $4.55
Continue to order more sandwich? (y/n): For your reference, the date and time is created by the following statements.
Date now = new Date();
DateFormat defaultDate = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String time = defaultDate.format(now); Multiple vegetables are separated by commas
Select meat [1, 5]: 4
Enter customer's name: John Smith
Besides showing on monitor, the same order line content is written (appended) to a text file named orderline.txt and each order line occupies one line in the text file. Here is a specific example for an order in the orderline.txt.
2016/07/05 20:34:17 John Smith Organic Bread lettuce, tomatoes, green peppers Roast Beef $4.55
Your program needs to create the output file, named orderline.txt, if it doesn’t exist yet, and later appends (not overwrite) order line information to the file. So next time when your program is executed, new order information will be appended to the orderline.txt file. You must use a relative path when creating an output stream writer object. For simplicity, we don’t record any information about the sales clerk and one order includes only one sandwich.
6. Repeating the order process
Continue to order more sandwich? (y/n):
If the user enters y or Y in the above prompt, the whole order process repeats by asking the user to select a sandwich bread, vegetable(s), meat, and enter a customer name, etc.
Design requirements (program should contain three classes):
You must have at least the following java classes. You may have additional classes if you want.
[1] a Sandwich class to simulate the sandwich entity in real world, which has attributes of bread, vegetables, meat, and price of the sandwich, and corresponding methods.
[2] an OrderLine class to simulate the orderline. This class has attributes of customer name, sandwich object, and the string value of time stamp (refer to the prior sample code). This class also provides a method to append the content of an orderline’s content to the output text file, orderline.txt.
[3] a java application, named SandwichApp.java, that contains a main method. This class interacts with Sandwich and Orderline classes.
ONRDER ONLINE TEXT
Explanation / Answer
package com.koti.chegg;
import java.util.Scanner;
public class Store {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double totalPrice = 0.0;
System.out.println("======select sandwich bread======");
System.out.println("1 White Bread $1.5");
System.out.println("2 Wheat Bread $1.8");
System.out.println("3 French Bread $2.0");
System.out.println("4 Organic Bread $2.3");
System.out.println("5.quit");
System.out.println("enter your choice");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("enter the quantity");
int quantity = scanner.nextInt();
totalPrice = totalPrice + (quantity * 1.5);
break;
case 2:
System.out.println("enter the quantity");
int quantity1 = scanner.nextInt();
totalPrice = totalPrice + (quantity1 * 1.8);
break;
case 3:
System.out.println("enter the quantity");
int quantity2 = scanner.nextInt();
totalPrice = totalPrice + (quantity2 * 2.0);
break;
case 4:
System.out.println("enter the quantity");
int quantity3 = scanner.nextInt();
totalPrice = totalPrice + (quantity3 * 2.3);
break;
case 5:
System.exit(0);
break;
default:
System.out.println("you choosen wrong option");
System.out.println("thanks for visiting......");
break;
}
System.out.println("=== Select Sandwich Vegetables: ===");
System.out.println("1 red onions $0.10");
System.out.println("2 olives $0.10");
System.out.println("3 pickles $0.10");
System.out.println("4 lettuce $0.20");
System.out.println("5 green peppers $0.25");
System.out.println("6 tomatoes $0.30");
System.out.println("7 cheese $0.49");
System.out.println("8 Quit");
System.out.println("vegetable selection[1:8]");
int choice1 = scanner.nextInt();
switch (choice1) {
case 1:
totalPrice = totalPrice + 0.10;
break;
case 2:
totalPrice = totalPrice + 0.10;
break;
case 3:
totalPrice = totalPrice + 0.10;
break;
case 4:
totalPrice = totalPrice + 0.20;
break;
case 5:
totalPrice = totalPrice + 0.25;
break;
case 6:
totalPrice = totalPrice + 0.30;
break;
case 7:
totalPrice = totalPrice + 0.49;
break;
case 8:
System.exit(0);
break;
default:
System.out.println("thanks for visiting.......");
}
System.out.println("=== Select Sandwich Meat: ===");
System.out.println("1 Ham $0.9");
System.out.println("2 Roasted Chicken Breast $1.0");
System.out.println("3 Turkey Breast $1.1");
System.out.println("4 Roast Beef $1.5");
System.out.println("5 Quit meat selection");
System.out.println("select meat [1:5]");
int choice2 = scanner.nextInt();
switch (choice2) {
case 1:
totalPrice = totalPrice + 0.9;
break;
case 2:
totalPrice = totalPrice + 1.0;
break;
case 3:
totalPrice = totalPrice + 1.1;
break;
case 4:
totalPrice = totalPrice + 1.5;
break;
case 5:
System.exit(0);
break;
default:
System.out.println("thanks for visiting");
break;
}
System.out.println("the total price is $"+totalPrice);
}
}
output
======select sandwich bread======
1 White Bread $1.5
2 Wheat Bread $1.8
3 French Bread $2.0
4 Organic Bread $2.3
5.quit
enter your choice
1
enter the quantity
3
=== Select Sandwich Vegetables: ===
1 red onions $0.10
2 olives $0.10
3 pickles $0.10
4 lettuce $0.20
5 green peppers $0.25
6 tomatoes $0.30
7 cheese $0.49
8 Quit
vegetable selection[1:8]
7
=== Select Sandwich Meat: ===
1 Ham $0.9
2 Roasted Chicken Breast $1.0
3 Turkey Breast $1.1
4 Roast Beef $1.5
5 Quit meat selection
select meat [1:5]
4
the total price is $6.49
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.