Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RestaurantBookingSystem
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sultan.khalifa
RestaurantBookingSystem
Commits
a80f3c9c
Commit
a80f3c9c
authored
Nov 15, 2020
by
Sully Khalifa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formative.
parent
2e56e735
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
440 additions
and
118 deletions
+440
-118
RestaurantBookingSystem.java
RestaurantBookingSystem/src/RestaurantBookingSystem.java
+440
-118
No files found.
RestaurantBookingSystem/src/RestaurantBookingSystem.java
View file @
a80f3c9c
import
java.util.ArrayList
;
import
java.util.Scanner
;
/*Algorithm
*
*
* 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
Table for the cart, where a customer can store selected item before payment
Also the cart has to capture these components of the items.
Start
-0- Welcome to the restaurant message
-1- Customer initial input
Ask customer to enter their name
-2- Ask customer if they would like to choose a seat from the unassigned seats.
-3- Create two dimensional arrays (string) to display the seat layout
If seats are not assigned, assign the seat to customer else display "XX" to indicate that the assigned seat is no longer available.
-4- If seats are available, assign to customers else display "Sorry there is no available seat at this time".
-5- Display a list of available food
-6- interface where a customer can choose one of the following options:
select an item
remove an item from a basket
check out (for payment)
exit.
-7- Create a temp basket
-8- make a payment for selected basket items
enter amount for payment
clear basket.
-9- Confirmation displaying:
customer's name.
seat number
list of ordered items
total cost of the order.
-1- Login system
Ask user enter username and password
Take the username and password
Check if it is correct login
else show a message that invalid username or password.
-2- List of products: -method
Name Code Price
-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
if available add it to the cart
else show a message out of stock
-4- Show cart with the total
-- Expand this as a method
*
*/
public
class
RestaurantBookingSystem
{
public
static
void
main
(
String
[]
args
)
{
// A facility for getting input
static
Scanner
input
=
new
Scanner
(
System
.
in
);
// 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, from Week 04
static
ArrayList
<
String
>
itemName
=
new
ArrayList
<
String
>();
// name
static
ArrayList
<
Integer
>
itemCode
=
new
ArrayList
<
Integer
>();
// code
static
ArrayList
<
Float
>
itemPrice
=
new
ArrayList
<
Float
>();
// price
static
ArrayList
<
Integer
>
itemQty
=
new
ArrayList
<
Integer
>();
// Quantity
static
ArrayList
<
String
>
itemDescription
=
new
ArrayList
<
String
>();
// Description
int
newUnit
=
10
;
}
}
import
java.util.Scanner
;
import
java.util.ArrayList
;
import
java.util.ListIterator
;
import
java.util.Random
;
/* Algorithm:
*
* Start
-Welcome to the restaurant message.
-Customer initial name input.
-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.
Check if user input is number 1 display the 2d array of tables
-display all tables using a method.
- take user input.
-assign selected table based on the input. (using a method)
otherwise book a random table.
-Ask customer if they want another table booked or continue.
- if option 9 is selected:
Display all tables
assign selected table (using a method)
If option 0 is selected:
Display a message showing the food menu.
else any other input will display an Invalid input message.
-display menu.
-while loop based on Boolean true value.
-print a message asking customer to enter the product code or 0 for payment.
-take the user input item code.
-if loop to check the user input
In case the user press 0
The final basket will be displayed.
-break to terminate the while loop
-Otherwise continue the if loop.
-Take user input for quantity.
if loop to check if the item is in stock.
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
;
}
//Basket class
class
Basket
{
String
name
;
int
code
;
double
price
;
int
qty
;
}
public
class
RestaurantBookingSystem
{
// Declared the share variable outside main method, such that we can use them in other methods
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
// an input facility
static
Scanner
input
=
new
Scanner
(
System
.
in
);
// 2d array that contains all tables.
static
String
tables
[][]
=
{
{
" [00] "
,
" [01] "
,
" [02] "
,
" [03] "
,
" [04] "
,
" [05] "
,
" [06] "
},
{
" [07] "
,
" [08] "
,
" [09] "
,
" [10] "
,
" [11] "
,
" [12] "
,
" [13] "
+
" \n "
},
{
" [14] "
,
" [15] "
,
" [16] "
,
" [17] "
,
" [18] "
,
" [19] "
,
" [20] "
},
{
" [21] "
,
" [22] "
,
" [23] "
,
" [24] "
,
" [25] "
,
" [26] "
,
" [27] "
+
" \n "
},
{
" [28] "
,
" [29] "
,
" [30] "
,
" [31] "
,
" [32] "
,
" [33] "
,
" [34] "
},
{
" [35] "
,
" [36] "
,
" [37] "
,
" [38] "
,
" [39] "
,
" [40] "
,
" [41] "
}};
// 2d array that contains reservation info for tables.
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment