-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurant.java
More file actions
207 lines (181 loc) · 5.98 KB
/
Restaurant.java
File metadata and controls
207 lines (181 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import java.util.ArrayList;
import java.awt.Color;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
/**
* Restaurant is the class used to "build" a new restaurant. The length and width tell the program how long and wide the grid should be
*/
public class Restaurant {
private int capacity;
private int length;
private int width;
private Color[][] colorSeat;
private String name;
//constructors
public Restaurant(){
length = 20;
width = 20;
capacity = (length * width);
name = null;
colorSeat = new Color[width][length];
createTables();
}
public Restaurant(int length, int width, String name){
this.length = length;
this.width = length;
this.capacity = (length * width);
this.name = name;
colorSeat = new Color[width][length];
createTables();
}
/**
* gets number of seats available at restaraunt
* ask Mr. Jacoby about class design and inheritance because we don't need to inherit the functions --> should they be public?
*/
public int getCapacity(){
return capacity;
}
public void addCapacity(int num){
capacity += num;
}
public int getLength(){
return length;
}
public int getWidth(){
return width;
}
public String toString(){
String res = "Patron's name: +" + name + "\n Number of seats: " + capacity;
return res;
}
public static Color randomColor(){
int red = (int)(Math.random() * 256);
int green = (int)(Math.random() * 256);
int blue = (int)(Math.random() * 256);
Color random = new Color(red, green, blue);
return random;
}
/**
* createTables sets every table in the restaurant to white using a 2D array
* the program later goes through and asseses whether or not a space is white to see if a table can be placed there
*/
public void createTables(){
StdDraw.setScale(0, length);
for(int r = 0; r < width; r++){
for(int c = 0; c < length; c++){
StdDraw.setPenColor(StdDraw.WHITE);
colorSeat[r][c] = StdDraw.WHITE;
StdDraw.filledSquare(r + 0.5, c + 0.5, 0.4);
StdDraw.setPenColor(StdDraw.WHITE);
}
}
}
/**
* the groupTable method is used to plot the reservations on the standard draw grid
* it goes through and assesses whether a square is white (available) or another color (unavailable)
* and then plots the tables accordingly
* @param res is needed for the program to know which reservation it's plotting
*/
/*public void groupTable(Reservation res){
if(res.getNumGuests()%2 != 0){
res.addGuests(1);
}
int side = res.getNumGuests()/2;
int total = res.getNumGuests();
Color current = randomColor();
for(int r = 0; r < width; r++){
for(int c = 0; c < length; c++){
if(colorSeat[r][c] == StdDraw.WHITE){
StdDraw.setPenColor(current);
colorSeat[r][c] = current;
StdDraw.filledSquare(r + 0.5, c + 0.5, 0.4);
total--;
}
if(total == side || total == 0){
break;
}
}
if(total == 0){
break;
}
}
}*/
public void groupTable(Reservation res){
if(res.getNumGuests()%2 != 0){
res.addGuests(1);
}
int side = res.getNumGuests()/2;
int total = res.getNumGuests();
Color current = randomColor();
int r = 0;
int c = 0;
while(r < width){
while(c < length){
if(colorSeat[r][c] == StdDraw.WHITE){
StdDraw.setPenColor(current);
colorSeat[r][c] = current;
StdDraw.filledSquare(r + 0.5, c + 0.5, 0.4);
total--;
}else if (total != side || total != 0){
c++;
}
if(total == side || total == 0){
//r++;
//c++;
break;
}
}
if(total == 0){
r = 0;
c = 0;
break;
}
}
}
public static void main(String[] args){
Restaurant First = new Restaurant(10, 10, "First");
Scanner scan = new Scanner(System.in);
Map<String, Reservation> ReservationsbyNames = new HashMap<>();
int numChoice = 4;
while(numChoice != -1){
//newReservation();
System.out.println("Hello! Are you looking to create a reservation? Please click 1. If you're looking for a reservation, click 2. If you want to change your reservation click 3. Click -1 to stop");
numChoice = scan.nextInt();
if(numChoice == 1){
System.out.println("What is your name?");
scan.nextLine();
String name = scan.nextLine();
System.out.println("What date would you like to make your reservation?");
String date = scan.nextLine();
System.out.println("What time?");
String time = scan.nextLine();
System.out.println("What is your phone number?");
String phoneNum = scan.nextLine();
System.out.println("How many guests?");
int guests = scan.nextInt();
Reservation res = new Reservation(name, phoneNum, time, date, guests);
System.out.print("Just to confirm. This is your reservation:" +res+"y/n?");
scan.nextLine();
String confirm = scan.nextLine();
if(confirm.equals("y")){
ReservationsbyNames.put(name, res);
//First.createTables();
First.groupTable(res);
}
}else if(numChoice == 2){
scan.nextLine();
System.out.println("Who's name are you looking for?");
String lookName = scan.nextLine();
System.out.print(lookName + "'s reservation is "+ReservationsbyNames.get(lookName));
}else if(numChoice == 3){
scan.nextLine();
System.out.println("What is your name?");
String resName = scan.nextLine();
System.out.print("Your reservation is "+ReservationsbyNames.get(resName));
}
}
System.out.print(First);
StdDraw.show();
}
}