Commit b22bbfd5 authored by harry's avatar harry

Main Version of Restaurant Assessment

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RESTAURANTASMNT</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
//This is a program which simulates selecting a table and ordering at a restaurant.
//The program will begin by presenting a grid of 42 seats in a string type 2 dimensional array.
//The program will then ask the user to select a seat by method of choosing a grid reference(as labelled).
//Upon successful seat selection the program will present a menu to the user.
//the program will then proceed to ask the user to select an option from a list of 5.
//The options will be, view order, select items for order, remove from order, pay for order, or exit, which voids the transaction.
//Upon completion of the process the program will reset and revert back to it's initial state for the next operation
// ----------------------------------------------------------------------------------------------------------------------------------------
//importing the java scanner for user input
import java.util.Scanner;
import java.util.ArrayList;
//the class within which this program will function
public class ASMNT {
// setting up for user input
static Scanner input = new Scanner (System.in);
//2 dimensional array to represent restaurant seating plan to assist with seat selection
static String[][] floor = {
{"0", " 1", " 2", " 3", " 4", " 5", " 6", " 7"},
{"1: ","[01]","[02]","[03]","[04]","[05]","[06]","[07]"},
{"2: ","[08]","[09]","[10]","[11]","[12]","[13]","[14]"},
{"3: ","[15]","[16]","[17]","[18]","[19]","[20]","[21]"},
{"4: ","[22]","[23]","[24]","[25]","[26]","[27]","[28]"},
{"5: ","[29]","[30]","[31]","[32]","[33]","[34]","[35]"},
{"6: ","[36]","[37]","[38]","[39]","[40]","[41]","[42]"}};
// defining of char values x and y for grid-based seat selection
static char x;
static char y;
// defining string that will replace seat number when seat is occupied
static String seat = "[XX]";
//defining of variable to store name
static String name;
//defining of string which will be used to store the seat number for end report
static String selection;
// defining of variable used in order removal method
static int index;
//array for the set menu, which will be defined and added to later on in the program.
static ArrayList<String> itemName = new ArrayList<String>();//Name
static ArrayList<Integer> itemCode = new ArrayList<Integer>();//Item Code
static ArrayList<Float> itemPrice = new ArrayList<Float>();// Price
static ArrayList<Integer> itemQty = new ArrayList<Integer>();// Quantity
// Array for the restaurant order
static ArrayList<String> orderName = new ArrayList<String>();// Name
static ArrayList<Integer> orderCode = new ArrayList<Integer>();//Item code
static ArrayList<Float> orderPrice = new ArrayList<Float>();// Price
static ArrayList<Integer> orderQty = new ArrayList<Integer>();// Quantity
// first method which displays floor array to show all seats
public static void displayFloor() {
for(int i = 0; i<7; i++) {
for(int j = 0; j<8; j++) {
System.out.print(floor[i][j]);
}
System.out.println();
}
}
private static void askName() {// Asks user for their name and stores in a variable to be used in end report
System.out.println("Please can I take a surname?");
name = input.next();
}
// second method for process of seat selection
//asks customer for a row and column value for seat selection
//grid reference points added in to shift array values away from 0 and minimise user confusion
private static boolean selectSeat() {
// while loop to automatically re-launch method should seat selection fail
while(true) {
System.out.println("Please choose a table. Your seat will be marked with an 'XX'");
System.out.println("Please choose a row (1 - 6)");
x = (char )input.nextInt();
System.out.println("Please choose a column (1 - 7)");
y = (char) input.nextInt();
//condition to check if seat selected is already taken
if (floor[x][y]== "[XX]") {
System.out.println("This seat is already taken. Please select another.");
}
//condition to assign available seat to customer
// takes seat number and stores in variable, replaces seat number with "[XX]"as detailed above
else {
selection = floor[x][y];
floor[x][y] = seat;
return true;
}
}
}
// third method which checks for a full floor, runs passively for each iteration until needed
private static boolean checkfullFloor() {
for(int i=0; i < 7; i++) {
for(int j=0; j<8;) {
if (floor[i][j] == "[XX]") {// error message shown when all seats are full and none more can be selected.
System.out.println("There are no more seats available today");
return true;}
else {
return false;
}
}
}
return false;
}// fourth method which takes the user input for menu items and adds them to the temporary order
private static void addToOrder(int tempOrdercode, int tempOrderQuant) {
// fetches each piece of data depending on user input
orderCode.add(tempOrdercode);
orderName.add(itemName.get(tempOrdercode));
orderPrice.add((float) (tempOrderQuant * itemPrice.get(tempOrdercode)));
orderQty.add((int) tempOrderQuant);
}
// fifth method which removes items from the order based on user input.
private static void rmvFromOrder() {
System.out.println("Which part of your order would you like to remove? (0 for 1st line, 1 for 2nd line etc.)");
index = input.nextInt();
orderCode.remove(index);
orderName.remove(index);
orderPrice.remove(index);
orderQty.remove(index);
}
// sixth method which is used in payment or exit sections later on to clear the order after each loop of the program
// without this the orders would stack after each run of the program
private static void clrOrder() {
orderCode.clear();
orderName.clear();
orderPrice.clear();
orderQty.clear();
}
// seventh method which accumulates some of the other functions to produce a summary of the user experience
private static void showSummary() {
System.out.println("Your summary is as follows: ");
System.out.println(" ");
System.out.println("SURNAME: " + name);
System.out.println(" ");
System.out.println("TABLE: " + selection);
System.out.println(" ");
System.out.println("ORDER: ");
showOrder();
System.out.println(" ");
System.out.print("COST: ");
calcCost();
}
//eighth method to show the user's order in its current state upon request
private static void showOrder() {
System.out.println( "Code \t Name \t\t Price \t\tQty" );
for( int i=0; i< orderName.size(); i++ ) {
System.out.println(orderCode.get(i) + " \t " + orderName.get(i) + "\t "
+ orderPrice.get(i) + " \t\t" + orderQty.get(i));
}
}
// ninth method which calculates the total cost of the order and processes payment from user
// recognises value of user payment and either void the order or processes change
private static void Processpayment() {
float cost = 0, amount;
for( int i=0; i< orderName.size(); i++ ) {
cost += orderPrice.get(i);
}
System.out.println("The total cost is " + cost );
System.out.println("That will be £" + cost + ", Please.");
amount = input.nextFloat();
if(amount >=cost ) {
System.out.println("Your change is £" + (amount - cost ) );
System.out.println("Thank you for dining with us.");
}
else {
System.out.println("Payment amount invalid, your payment does not meet the cost of your order.");
System.out.println(" ");
System.out.println("I'm sorry but we must void your order for today.");
}
}
//tenth method which calculates the cost independently so that it can be used in the summary
//more easily that out of the payment method
private static void calcCost(){
float cost = 0;
for( int i=0; i< orderName.size(); i++ ) {
cost += orderPrice.get(i);
}
System.out.println("£" + cost );
}
// eleventh method which gives the user a list of options. selection process in main method below.
public static void showoptions() {
System.out.println(" ");
System.out.println("Please select an option from the list below");
System.out.println("1. View Your Order");
System.out.println("2. Select your food order");
System.out.println("3. Remove an Item from your order");
System.out.println("4. Pay for your order");
System.out.println("5. Exit");
}
//main method. loop defined here to automatically continue the program until all seats are full
//this means that when initial service is completed for a customer, the program reverts back to its initial state for the next customer
public static void main(String[] args) {
//defining of key variables in the section
int tempOrdercode;
int tempOrderQuant;
int option = 0;
// adding the menu items to the menu array. This is done outside of the main loop so as to avoid stacking
// or duplication of the menu each time it runs
itemName.add("Pizza ");
itemCode.add(0);
itemPrice.add((float) 10);
itemQty.add(50);
itemName.add("Steak ");
itemCode.add(1);
itemPrice.add((float) 7);
itemQty.add(50);
itemName.add("Sandwich");
itemCode.add(2);
itemPrice.add((float) 5);
itemQty.add(50);
itemName.add("Water ");
itemCode.add(3);
itemPrice.add((float) 1);
itemQty.add(30);
itemName.add("Soft Drink");
itemCode.add(4);
itemPrice.add((float) 2);
itemQty.add(30);
itemName.add("Tea ");
itemCode.add(5);
itemPrice.add((float) 2);
itemQty.add(20);
itemName.add("Coffee");
itemCode.add(6);
itemPrice.add((float) 2);
itemQty.add(20);
itemName.add("Ice Cream");
itemCode.add(7);
itemPrice.add((float) 2);
itemQty.add(20);
itemName.add("Chocolate");
itemCode.add(8);
itemPrice.add((float) 2);
itemQty.add(20);
for(int k=0; k<=41; k++) {
askName();// asks for and stores the user's name
checkfullFloor();// checks the floor is not full
displayFloor();//show the floor
selectSeat();// allows for seat to be selected, also stores seat number in variable
displayFloor();// shows new floor with seat marked for confirmation
// print menu with items defined above
System.out.println(" ");
System.out.println("Here is your menu:");
System.out.println( "No. \t\t Item \t\t\t Price \t\t Quantity" );
for(int i=0; i< itemName.size(); i++) {
System.out.println(itemCode.get(i) + " \t\t " + itemName.get(i) + " \t\t "
+ itemPrice.get(i) + " \t\t " + itemQty.get(i));
}
//loop giving the user 5 options for what to do. will show after each completed choice until program ends.
// 1 view order, 2 select food, 3 remove from order, 4 pay for order, 5 exit.
while(true) {
showoptions();
option = input.nextInt();
if (option == 1) {
showOrder();// shows order if 1 i selected
}
else if (option == 2) {// asks user to select menu items and adds them to temporary order
while(true) {
System.out.println("Please enter a food item No. to select your food");
tempOrdercode = input.nextInt();
System.out.println("How many would you like?");// asks for quantity
tempOrderQuant = input.nextInt();
if(itemQty.get(tempOrdercode) >= tempOrderQuant ) { // checks if quantity is available
addToOrder(tempOrdercode, tempOrderQuant);// runs add to order method
}
else if (tempOrdercode == 0);
showOrder();
break;
}
}
if (option == 3) {// makes use of removal function
rmvFromOrder();
}
else if (option == 4) {
// shows the final order
showOrder();
Processpayment();//runs method for payment
System.out.println(" ");// leaves gap for layout
showSummary();//shows final summary
clrOrder();// passively clears temporary order in preparation for next run
break;// ends code and starts again
}
else if (option == 5){// ends code and starts again, also shows final screen with orddr summary and completion status
System.out.println("Goodbye, Thankyou for visiting.");
System.out.println("STATUS: NOT PAID, VOID ORDER");
System.out.println(" ");
showSummary();
System.out.println(" ");
System.out.println("VOID");
clrOrder();
break;
}
if (k == 42) {
System.out.print("Sorry, we are full for this evening");
break;// recognises when all seats must be full and automatically breaks program, just here in case earlier method fails
}
}
}
}
}
// program end
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