Commit c24ec7d6 authored by quinnhaigh's avatar quinnhaigh

2nd commit

parent dac2634c
package foodOrderingSystem1;
public class FoodOrderingSystem1 {
import java.util.ArrayList;
import java.util.Scanner;
public class FoodOrderingSystem1{
//array for Storage of menu items
static ArrayList<Integer> itemCode = new ArrayList<Integer>();
static ArrayList<String> itemName = new ArrayList<String>();
static ArrayList<Integer> itemQty = new ArrayList<Integer>();
static ArrayList<Double> itemPrice = new ArrayList<Double>();
//create temporary storage for basket which contains all details of items.
static ArrayList<Integer> basketCode = new ArrayList<Integer>();
static ArrayList<String> basketName = new ArrayList<String>();
static ArrayList<Integer> basketQty = new ArrayList<Integer>();
static ArrayList<Double> basketPrice = new ArrayList<Double>();
static ArrayList<Double> basketCost = new ArrayList<Double>();
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
//add menu choices
itemCode.add(1);
itemName.add("Pizza ");
itemQty.add(50);
itemPrice.add(10.0);
itemCode.add(2);
itemName.add("Burger ");
itemQty.add(50);
itemPrice.add(7.0);
itemCode.add(3);
itemName.add("Sandwich ");
itemQty.add(50);
itemPrice.add(5.0);
itemCode.add(4);
itemName.add("Water ");
itemQty.add(30);
itemPrice.add(1.0);
itemCode.add(5);
itemName.add("Soft drink");
itemQty.add(30);
itemPrice.add(2.0);
itemCode.add(6);
itemName.add("Tea ");
itemQty.add(20);
itemPrice.add(2.0);
itemCode.add(7);
itemName.add("Coffee ");
itemQty.add(20);
itemPrice.add(2.0);
itemCode.add(8);
itemName.add("Ice cream ");
itemQty.add(20);
itemPrice.add(2.0);
itemCode.add(9);
itemName.add("Chocolate ");
itemQty.add(20);
itemPrice.add(2.0);
home();
}
//Create menu options for which service they would like to use.
public static void home() {
String userChoice;
while(true) {
System.out.println("Which service would you like:\n"
+ "1: Look at the menu,\n"
+ "2: Choose which items you would like, \n"
+ "3: View or edit basket,\n"
+ "4: Checkout, \n"
+ "5: Quit");
userChoice = input.next();
switch(userChoice) {
case"1":
lookAtMenu();
break;
case"2":
chooseItem();
break;
case"3":
viewAndEditBasket();
break;
case"4":
checkOut();
break;
case"5":
System.out.println("Thankyou for trying our page.");
return;
default:
System.out.println("Invalid input, valid inputs are 1, 2 ,3,4,5");
}
}
}
//method for viewing the menu
public static void lookAtMenu() {
int size =itemName.size();
System.out.println("----------Menu--------");
for(int i=0; i<size; i++) {
System.out.println(itemCode.get(i) + " " + itemName.get(i) + " " +
itemQty.get(i) + " £" + itemPrice.get(i));
}
System.out.println("---------------");
}
//end of while loop
public static void viewAndEditBasket() {
String userInput;
int basketSize = basketName.size();
System.out.println("--------Basket--------");
for(int i=0; i<basketSize; i++) {
System.out.println(basketCode.get(i) + "\t" + basketName.get(i) + "\t£" + basketPrice.get(i)
+ "\t" + basketQty.get(i) + "\t");
}
System.out.println("Would you like to delete any items from your basket? \n"
+ "1 for yes, \n"
+ "2 for paymnet, \n"
+ "3 for no,");
userInput = input.next();
switch(userInput) {
case"1":
editBasket();
break;
case"2":
checkOut();
break;
case"3":
return;
default:
System.out.println("Valid inputs are 1,2 or 3, please input correct value.");
}
}
//method for editing basket.
private static void editBasket() {
//select item code.
System.out.println("Which item would you like to delete?");
int userCode = input.nextInt();
//quantity to delete.
System.out.println("How many would you like to delete?");
int userQty = input.nextInt();
//get position in storage.
int position = basketCode.lastIndexOf(userCode);
if(userQty<basketQty.get(position)) {
//remove item from basket
itemCode.remove(basketCode.get(position));
itemName.remove(basketName.get(position));
itemQty.remove(userQty);
itemPrice.remove(basketPrice.get(position));
basketCost.remove(itemPrice.get(position) * userQty);
//add item back to menu
itemQty.set(position,itemQty.get(position) + userQty);
}
}
public static void chooseItem() {
//lookAtMenu();
while(true) {
//get item code.
System.out.println("Enter item code to select item or 0 for payment");
int code = input.nextInt();
// setting payment.
if(code == 0){
checkOut(); // for payment.
break;
}
//get quantity
System.out.println("How many would you like?");
int qty = input.nextInt();
//get position of the choice in storage.
int position = itemCode.lastIndexOf(code);
//check if required amount available.
if(qty<itemQty.get(position)) {
//add item to basket.
basketCode.add(itemCode.get(position));
basketName.add(itemName.get(position));
basketQty.add(qty);
basketPrice.add(itemPrice.get(position));
basketCost.add(itemPrice.get(position) * qty);
//reduce the quantity.
itemQty.set(position,itemQty.get(position) - qty);
}
else
System.out.println("Unfortunately there are only" + itemQty.get(position) + "available");
return;
}//end of while loop for choice
}
//method for payment
public static void checkOut() {
//display basket total cost.
double total = 0;
//get basket size.
int basketSize = basketName.size();
System.out.println("--------Basket--------");
for(int i=0; i<basketSize; i++) {
System.out.println(basketCode.get(i) + "\t" + basketName.get(i) + "\t£" + basketPrice.get(i)
+ "\t" + basketQty.get(i) + "\t");
//accumulate total for basket
total = total + basketCost.get(i);
}
//print the total
System.out.println("Total = £" + total);
System.out.println("If you are not finished with your order go to choose items.");
home();
//get payment
System.out.println("Please enter the payment");
double payment = input.nextDouble();
//work out change
double change = payment - total;
System.out.println(change);
if(change > 0) {
System.out.println("Please take you change and your items and have a nice day.");
}
else if(change == 0) {
System.out.println("Please take you items and have a nice day.");
}
else
System.out.println("Your Balance is" + change);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment