You are on page 1of 3

package food.ordering.

system;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FoodOrderingSystem {

static Scanner scan = new Scanner(System.in);


static int choice;
static float burgerPrice = 45, friesPrice = 30, milkteaPrice = 60;
static float totalPrice = 0;
static float currentPrice = 0;
static float quantity;

static List<String> orderlist = new ArrayList<>();

int orderAgain = 0;

public static void main(String[] args) {


/*
1. Display Menu
2. Choose Order
3. Multiply Order
4. Order again? if yes, go back to 1, if no, proceed to 5
5. Display, orders, display total amount
6. Transact again? if yes, back to 1, if no exit
*/
separator();
System.out.println("\t\t Food Ordering System");

do{

separator();
System.out.println("Menu:\n"
+ "[1]Burger = 45\n"
+ "[2]Fries = 30\n"
+ "[3]Milktea = 60\n");

Choice();

switch(choice){
case 1:
currentPrice = burgerPrice;
orderlist.add("Burger = p45");
break;
case 2:
currentPrice = friesPrice;
orderlist.add("Fries = P30");
break;
case 3:
currentPrice = milkteaPrice;
orderlist.add("Milktea = P60");
break;
default:
System.out.println("Invalid Input");
}
separator();
multiplyTo();
orderlist.set(orderlist.size()-1, orderlist.get(orderlist.size()-1) + " -
x" + quantity);

separator();
System.out.println(" Do you want to order again? [1]Yes | [2] No:");
separator();
Choice();

}while(choice == 1);

separator();
int count = 1;
for (String display : orderlist){
System.out.println(count+ "." + display);
count++;

}
separator();
System.out.println("The total price is: "+totalPrice);
separator();
}
static void multiplyTo(){
while(true){
try{
System.out.println("mutiply To: ");
String multiplyTo = scan.next();
quantity = Integer.parseInt(multiplyTo);
if (quantity <= 0){
System.out.println(" Must be positive number.");
separator();
}else{
totalPrice += currentPrice * quantity;
break;
}

}catch(NumberFormatException nfe){

}
}
}

static void Choice(){


while(true){
try{
System.out.print(":");
String Choice = scan.next();
choice = Integer.parseInt(Choice);
break;
}catch(NumberFormatException nfe){
separator();
System.out.println("Invalid Input Most Be integer");
}
}
}
static void separator(){
for (int i = 0; i<25; i++){
System.out.print("--");
}
System.out.println("");

You might also like