Commit a80f3c9c authored by Sully Khalifa's avatar Sully Khalifa

Formative.

parent 2e56e735
import java.util.ArrayList; import java.util.Scanner;
import java.util.Scanner; import java.util.ArrayList;
import java.util.ListIterator;
/*Algorithm import java.util.Random;
*
*
* Generic description of the items: name, code, price, quantity and description /* Algorithm:
*
Database for the products/items: has to reflects all these components of the items * Start
-Welcome to the restaurant message.
-Customer initial name input.
Table for the cart, where a customer can store selected item before payment
Also the cart has to capture these components of the items. -Ask customer to enter their name.
-Ask customer if they would like to book a table from the unassigned list or a random selection.
- take user input.
Start Check if user input is number 1 display the 2d array of tables
-0- Welcome to the restaurant message -display all tables using a method.
-1- Customer initial input - take user input.
Ask customer to enter their name -assign selected table based on the input. (using a method)
-2- Ask customer if they would like to choose a seat from the unassigned seats. otherwise book a random table.
-3- Create two dimensional arrays (string) to display the seat layout -Ask customer if they want another table booked or continue.
If seats are not assigned, assign the seat to customer else display "XX" to indicate that the assigned seat is no longer available. - if option 9 is selected:
-4- If seats are available, assign to customers else display "Sorry there is no available seat at this time". Display all tables
-5- Display a list of available food assign selected table (using a method)
-6- interface where a customer can choose one of the following options: If option 0 is selected:
select an item Display a message showing the food menu.
remove an item from a basket else any other input will display an Invalid input message.
check out (for payment) -display menu.
exit. -while loop based on Boolean true value.
-7- Create a temp basket -print a message asking customer to enter the product code or 0 for payment.
-8- make a payment for selected basket items -take the user input item code.
enter amount for payment -if loop to check the user input
clear basket. In case the user press 0
The final basket will be displayed.
-9- Confirmation displaying: -break to terminate the while loop
customer's name. -Otherwise continue the if loop.
seat number -Take user input for quantity.
list of ordered items if loop to check if the item is in stock.
total cost of the order. if available, it will be added
otherwise a print message will show Out of stock.
-Display the shopping basket.
-end. */
//Item class
class Item{
String name;
int code;
double price;
int qty;
}
-1- Login system //Basket class
Ask user enter username and password class Basket{
Take the username and password
Check if it is correct login String name;
else show a message that invalid username or password. int code;
-2- List of products: -method double price;
Name Code Price int qty;
-3- Select a product
Ask the user to enter item code
Entering item code }
Take the item code
Ask for the quantity
Check if it is available in the stock public class RestaurantBookingSystem {
if available add it to the cart
else show a message out of stock
-4- Show cart with the total // Declared the share variable outside main method, such that we can use them in other methods
-- Expand this as a method
* static int min = 1, max = 41, newTable = 1, cost = 0, x, y, random_int, code, qty, tempItemCode, tempItemQty, secondTable;
*/ static String tableArray, userName, name, tableInput;
static double price;
//Generic description of the items: name, code, price, quantity and description
//Database for the products/items: has to reflects all these components of the items
// An array or list to represent the database
static ArrayList<String> itemName = new ArrayList<String>(); // name
static ArrayList<Integer> itemCode = new ArrayList<Integer>(); // code
static ArrayList<Integer> itemPrice = new ArrayList<Integer>(); // price
static ArrayList<Integer> itemQty = new ArrayList<Integer>(); // Quantity
//Table for the cart, where a customer can store selected item before payment
//Also the cart has to capture these components of the items.
static ArrayList<String> basketName = new ArrayList<String>(); // name
static ArrayList<Integer> basketCode = new ArrayList<Integer>(); // code
static ArrayList<Integer> basketPrice = new ArrayList<Integer>(); // price
static ArrayList<Integer> basketQty = new ArrayList<Integer>(); // Quantity
public class RestaurantBookingSystem { // an input facility
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
// A facility for getting input // 2d array that contains all tables.
static Scanner input = new Scanner(System.in); static String tables [][] = {
{" [00] " , " [01] " , " [02] " , " [03] " , " [04] " , " [05] " , " [06] "},
// Generic description of the items: name, code, price, quantity and description {" [07] " , " [08] " , " [09] " , " [10] " , " [11] " , " [12] " , " [13] " + " \n "},
// Database for the products/items: has to reflects all these components of the items
// An array or list to represent the database, from Week 04 {" [14] " , " [15] " , " [16] " , " [17] " , " [18] " , " [19] " , " [20] "},
static ArrayList<String> itemName = new ArrayList<String>(); // name {" [21] " , " [22] " , " [23] " , " [24] " , " [25] " , " [26] " , " [27] " + " \n "},
static ArrayList<Integer> itemCode = new ArrayList<Integer>(); // code
static ArrayList<Float> itemPrice = new ArrayList<Float>(); // price {" [28] " , " [29] " , " [30] " , " [31] " , " [32] " , " [33] " , " [34] "},
static ArrayList<Integer> itemQty = new ArrayList<Integer>(); // Quantity {" [35] " , " [36] " , " [37] " , " [38] " , " [39] " , " [40] " , " [41] "}};
static ArrayList<String> itemDescription = new ArrayList<String>(); // Description
// 2d array that contains reservation info for tables.
int newUnit = 10; static boolean reservation [][] =
{{false, false, false, false, false, false, false},
} {false, false, false, false, false, false, false},
}
{false, false, false, false, false, false, false},
{false, false, false, false, false, false, false},
{false, false, false, false, false, false, false}};
//main method
public static void main(String[] args) {
// Definition of stocks
// ArrayList<Item> stocks = new ArrayList<Item>();
// Basket
// ArrayList<Item> basket = new ArrayList<Item>();
itemName.add("Pizza");
itemCode.add(1);
itemPrice.add((int) 10);
itemQty.add(50);
itemName.add("Steak");
itemCode.add(2);
itemPrice.add((int) 7);
itemQty.add(50);
itemName.add("Sandwich");
itemCode.add(3);
itemPrice.add((int) 5);
itemQty.add(50);
itemName.add("Water");
itemCode.add(4);
itemPrice.add((int) 1);
itemQty.add(30);
itemName.add("Soft drink");
itemCode.add(5);
itemPrice.add((int) 2);
itemQty.add(30);
itemName.add("Tea ");
itemCode.add(6);
itemPrice.add((int) 2);
itemQty.add(20);
itemName.add("Coffee");
itemCode.add(7);
itemPrice.add((int) 2);
itemQty.add(20);
itemName.add("Ice cream");
itemCode.add(8);
itemPrice.add((int) 2);
itemQty.add(20);
itemName.add("Chocolate");
itemCode.add(9);
itemPrice.add((int) 1);
itemQty.add(30);
//-----------------------------------------------------------------------------
//Welcome message to the customer
System.out.println("Welcome to the booking system > ");
System.out.println();
//taking user input.
System.out.println("Please enter your full-name> ");
userName = input.next();
System.out.println("Thank you, " + userName + ".");
System.out.println();
// a message to select the table booking options
System.out.println("If you wish to book a table press 1, or press 0 for random table allocation.");
int firstInput = input.nextInt();
//if loop to check user input.
if ( firstInput == 1) {
displayTable1();
assignTable(" [XX] ");
System.out.println();
displayTable1();
} else {
randomTable(); //a method for selecting a random table.
}
//additional table booking option.
System.out.println("If you would like to book another table please press 9 or press 0 to continue. ");
secondTable = input.nextInt();
//if loop in case the user select another table to book.
if( secondTable == 9) {
displayTable1();
assignTable(" [XX] ");
}else if (secondTable == 0){
//a message showing the main menu.
System.out.println("Thank you. Please see the below menu...>>> ");
System.out.println();
} else {
//a message showing displayed when the user input the incorrect number.
System.out.println("Invalid input. ");
}
itemList();
while(true) {
//-3- Select a product
//Ask the user to enter item code
System.out.println();
System.out.println("Please enter an item code to select the item or 0 for payment ");
// Entering item code
tempItemCode = input.nextInt() ;
if(tempItemCode == 0) {
paymentMethod();
// termination point
break;
}
else {
// Ask for the quantity
System.out.println("How many do you need? > ");
tempItemQty = input.nextInt();
// Check if it is available in the stock
if(itemQty.get(tempItemCode) >= tempItemQty ) {
// if available add it to the cart
addToBasket(tempItemCode, tempItemQty);
}
// else show a message out of stock
else{
System.out.println("Out of stock");
}
// Show cart with the total
displayBox();
}
}
System.out.println();
System.out.println("A confirmation receipt for " + userName + " ,Table number "
+ x + y + "Total cost " + cost );
} // Ending of main method
// --------------------------------------------------------------------------
// A method for displaying the shopping basket
private static void displayBox() {
// Name Code Price
System.out.println( "Code \t: Name \t: Price \t: Qty\t: " );
for( int i=0; i< basketName.size(); i++ ) {
System.out.println(basketCode.get(i) + " \t: " + basketName.get(i) + "\t: "
+ basketPrice.get(i) + " \t\t:" + basketQty.get(i) );
}
} // Ending of displaying box
// remove the specification of an item into a box
private static void removeFromBasket(int tempItemCode, int tempItemQty) {
basketCode.remove(tempItemCode);
basketName.remove( itemName.get(tempItemCode) );
basketQty.remove( tempItemQty);
basketPrice.remove( tempItemQty * itemPrice.get(tempItemCode));
} //------------- end of item removal method.
// Add the specification of an item into a box
private static void addToBasket(int tempItemCode, int tempItemQty) {
basketCode.add(tempItemCode);
basketName.add( itemName.get(tempItemCode) );
basketQty.add( tempItemQty);
basketPrice.add( tempItemQty * itemPrice.get(tempItemCode));
}
// A method for the payment
private static void paymentMethod() {
int amount;
for( int i=0; i< basketName.size(); i++ ) {
cost += basketPrice.get(i);
}
// Display the total cost
System.out.println("The total cost is " + cost );
// payment instructions
System.out.println("Please make a payment...>>> ");
amount = input.nextInt();
//check if the amount paid is greater than cost
if(amount > cost ) {
System.out.println("Your change is " + (amount - cost ) );
System.out.println("Thank you for shopping with us today! please collect your items.");
} else {
System.out.println("The payment has been rejected, please try again. ");
}
} // Ending of the payment method
//A method for displaying all tables
public static void displayTable1() {
for(int i =0; i<6; i++) {
for(int j=0; j<7; j++) {
System.out.print(tables[i][j]);
}
System.out.println();
}
System.out.println();
}
//A method for assigning tables
private static void assignTable( String tableInput) {
while(true){
System.out.println("Enter a table number from the numbers above with a space in between the digits ");
// Reads the positions
x = input.nextInt();
y = input.nextInt();
tables[x][y] = "[XX]";
// Check if the table is available before booking it.
if(reservation[x][y] == false) {
System.out.println("Your table is now booked.");
// Terminate the loop a for booking the table.
}
else {
System.out.println("The table is already booked.");
}
break;
}
// fill in the vacancy by assigning the selected table to the customer.
tables[x][y] = tableInput;
reservation [x][y] = true;
System.out.println();
} // Ending of the method assignTable ---------------------------------
//A method for random table allocation.
private static void randomTable() {
random_int = (int)(Math.random() * (max - min + 1) + min);
System.out.println("Your table number is 0"+random_int);
} // Ending of the method ---------------------------------
//A method for list of products.
private static void itemList () {
// Name Code Price Quantity Description
System.out.println( "Code\t: Name \t: Price \t:Qty " );
for( int i=0; i< itemName.size(); i++ ) {
System.out.println( itemCode.get(i) + " \t: " + itemName.get(i) + " \t: " + itemPrice.get(i) + "\t\t:" + itemQty.get(i) );
}
}
}
\ No newline at end of file
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