-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw.java
More file actions
57 lines (48 loc) · 1.53 KB
/
Draw.java
File metadata and controls
57 lines (48 loc) · 1.53 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
import java.awt.*;
public class Draw {
private int length;
private int width;
private Color[][] colorSeat;
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;
}
public void createTables(){
StdDraw.setScale(0, length);
for(int r = 0; r < length; r++){
for(int c = 0; c < width; c++){
StdDraw.setPenColor(StdDraw.WHITE);
colorSeat[r][c] = StdDraw.WHITE;
StdDraw.filledSquare(r + 0.5, c + 0.5, 0.4);
StdDraw.setPenColor(StdDraw.WHITE);
}
}
}
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;
}
}
}
}