This program is a java program where the main point is to build a little on-line
ID: 3689406 • Letter: T
Question
This program is a java program where the main point is to build a little on-line food shop. Try to use methods to complete functions.
Program requirements: A food market store invites you to help them build an on-line food order program. Customers can use this program to order food on-line.
The program should include at least 4 functionalities: 1) Add food in order; 2)Remove food from order; 3) Review order; 4) Check out the order. You can use a menu as a UI (user interface).
Assume there are 4 types of food: Hamburger ($8), Lemonade ($3), Chicken Wing ($1), and Pizza ($6). Customer can order any kinds of food, and any amount of them.
Scenario 1: Costumer A ordered 3 Hamburger and 2 Lemonade, and then removed 1 Hamburger and ordered 5 Chicken wings. Check them out finally.
Scenario 2: Costumer B ordered 10 chicken wings and 1 pizza, and then he reviewed his order,
and then add 1 more pizza. Check them out finally.
i) In the add food in order module, your program may need a menu too to show all sorts of food and their price. The input should be food ID and amount. Your program should record the information to calculate the total fee.
ii) In the review order module, all kinds of food information the customer ordered will be shown. The information includes unit price, amount, subtotal fee, and total fee.
iii) In the remove food from order module, customer can remove food from order. The input should be the food ID and amount. Your program should record the changed information.
iv) In the checking out module, the program will print out the bill (review information and tax fee and checkout fee). Checkout fee= total + tax. Taxfee = total * 7.77%. Taxrate: 7.77%. In addition, you can add other modules, such as customer login module, food delivery module, etc.
Output looks like the following:
This output is just an example. You may make it better.
Hint: You may need to declare several global variables to contain customer's order information, like the quantity of any food, the prices, and so on, so that your methods can use them directly. Or the methods pass the data to each other by parameters and returning data.
Hint: You may need the following methods to be created: functionMenu(), foodMenu(), add FoodToOrder(), removeFoodFromOrder(), reviewOrder(), and checkout().
Hint:In the main method, you may need a
sentinel control led loop to control the whole process.
Hint: Think about the situations that the customers mayinput a wrong character/number.
Explanation / Answer
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Scanner;
public class Shopping {
public static void main(String[] args) {
ArrayList<CartItem> shoppingCart = new ArrayList<CartItem>();
Scanner scan = new Scanner(System.in);
ArrayList<Integer> intList = new ArrayList<Integer>();
boolean keepGoing = true;
int choice = 0;
int input = 0;
int index=0;
int total = 0;
Integer item;
while(keepGoing)
{
System.out.println(" Menu - Managing a List");
System.out.println("1 Add food item ");
System.out.println("2 Remove food item ");
System.out.println("3 Review order");
System.out.println("4 Check order");
System.out.println("Select a menu option");
choice = scan.nextInt();
if (choice <1 || choice >4)
{
System.out.println("Enter a value between 1 and 4:");
}
else
{
switch (choice)
{
case 1:
//add an integer
System.out.println("Enter an item:");
input = scan.nextInt();
item = new Integer(input);
intList.add(item);
//intList.add(input);
break;
case 2:
//remove from the list
System.out.println("Enter an item to remove:");
input = scan.nextInt();
item = new Integer(input);
if (intList.contains(item))
{
intList.remove(item);
System.out.println(item + " has been removed.");
}
else
{
System.out.println(item + " was not found in your shopping cart.");
}
break;
case 3:
System.out.println(intList);
break;
case 4:
for (int i = 0; i<intList.size(); i++)
{
item = intList.get(i);
total = total + item.intValue();
}
System.out.println("Total is "+ total);
System.out.println("Goodbye");
keepGoing = false;
break;
}
}
}
}
}
void item_list()
{
struct food {
char *item;
double price;
int count;
} menu[] = {
"Hamburger", 2.25, 0,
"Lemonade", 1.00, 0,
"ChickenWing", 2.50, 0,
"Pizza", .95, 0,
};
double total(double index)
{
double price = 0.00;
price += 100 * index;
return price;
}
void print_menu(int max)
{
int i;
int c = 'A';
printf(" Welcome to Max's Hamburgers ");
fprintf(stdout, "%-10s%-10s%-24s%-14s ",
"Item", "Count", "ENTREES", "Price");
for (i = 0; i < max; i++) {
fprintf(stdout, "%-10c%-10d%-24s%-.2f ",c + i,
menu[i].count, menu[i].item, menu[i].price);
}
printf(" SELECT (A-P), R-RESET, - CORRECT, T-TIP, S-DISCOUNT, X-EXIT: ");
fflush(stdout);
}
void clear_data(int max)
{
int i;
for (i = 0; i < max; i++) {
menu[i].count = 0;
}
}
int main(void)
{
int max = sizeof(menu)/sizeof(struct food);
double sum = 0.00;
float tippercent = 0.00;
float discount = 0.00;
int c;
print_menu(max);
while ((c = getchar()) != EOF) {
switch(c)
{
case 'A': case 'B': case 'C': case 'D': case 'E':
menu[c - 'A'].count++;
sum += total(menu[c - 'A'].price);
break;
case 'R':
sum = 0.00;
tippercent = 0.00;
discount = 0.00;
clear_data(max);
break;
case 'S':
printf ("ENTER DISCOUNT ");
fflush(stdout);
scanf ("%f", &discount);
break;
case 'T':
printf ("ENTER TIP PERCENTAGE ");
fflush(stdout);
scanf ("%f", &tippercent);
break;
case 'X': case 'x':
sum = sum + (sum * (tippercent/100));
printf("**The final total is: %.2f ", (sum/100) - (discount/100));
exit(1);
default:
print_menu(max);
break;
}
}
exit(0);
system("pause");
return 0;
}
}
void delete_list()
{
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.