-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestaurant.java
168 lines (146 loc) · 4.66 KB
/
Restaurant.java
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
import java.util.ArrayList;
import java.util.List;
public class Restaurant {
int id;
String name;
double score;
String price;
double avgPrice;
String zip_code;
String category[] = new String[3];
int catCounter = 0;
List<Food> allFoods = new ArrayList<>();
public String[] getCategory() {
return category;
}
public List<Food> getAllFoods() {
return allFoods;
}
public Restaurant(int id, String name, double score, String zipcode, String catname[]) {
setId(id);
this.name = name;
this.score = score;
avgPrice = 0;
this.zip_code = zipcode;
for (int i = 0; i < catname.length; i++) {
if (catname[i] != null) {
setCategory(catname[i]);
}
}
}
public Restaurant(int id, String name, double score, String price, String zipcode, String catname[]) {
setId(id);
this.name = name;
this.score = score;
this.price = price;
avgPrice = 0;
if (price == "$" && avgPrice == 0) {
avgPrice = 5;
}
if (price == "$$" && avgPrice == 0) {
avgPrice = 14;
}
if (price == "$$$" && avgPrice == 0) {
avgPrice = 25;
}
this.zip_code = zipcode;
for (int i = 0; i < catname.length; i++) {
if (catname[i] != null) {
setCategory(catname[i]);
}
}
}
public void setCategory(String catName) {
if (catCounter < 3) {
category[catCounter] = catName;
catCounter++;
} else {
System.out.println("Category limit exeeds(3)");
}
return;
}
public int getCatCounter() {
return catCounter; // highest return 3 for 3 category
}
public void printCategory() {
for (String x : category) {
System.out.print("," + x);
}
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setscore(double score) {
this.score = score;
}
public double getscore() {
return this.score;
}
public String getPrice() {
return this.price;
}
public void setZipCode(String zipCode) {
this.zip_code = zipCode;
}
public String getzipCode() {
return this.zip_code;
}
public boolean isFoodAvailable(String cat, String foodname) {
for (Food f : allFoods) {
if (f.getCategory().equalsIgnoreCase(cat) && f.getfoodname().equalsIgnoreCase(foodname)) {
return true;
}
}
return false;
}
public void addFood(String cat, String foodname, double price) {
if (isFoodAvailable(cat, foodname)) {
System.out.println("Same category and Food exist in this restaurant already");
return;
}
allFoods.add(new Food(this.getId(), cat, foodname, price));
updatePrice();
}
private void updatePrice() { // call all food;
double totallprice = 0;
for (Food f : getAllFoods())
totallprice += f.getPrice();
avgPrice = totallprice / getAllFoods().size();
if (avgPrice >= 1 && avgPrice <= 10)
this.price = "$";
if (avgPrice >= 11 && avgPrice <= 20)
this.price = "$$";
if (avgPrice >= 21 && avgPrice <= 30)
this.price = "$$$";
}
public void DisplayRestaurant() {
System.out.println("Id: " + id + ", Restaurant Name: " + this.name + ", Score: " + score+", Price: "+this.price+", zipCode "+this.zip_code);
System.out.println("Categories: ");
for (int j = 0; j < getCatCounter(); j++) {
if (j == getCatCounter() - 1) {
System.out.println(getCategory()[j]);
break;
}
System.out.print(getCategory()[j] + " ,");
}
}
public void DisplayShortlyRestaurant(){
System.out.println("ID: "+this.id+", Name: "+this.name+", Score "+this.score+", price "+this.price+", zipcode: "+this.zip_code);
}
public void DisplayRestaurantFoods() {
System.out.println("Id: " + id + ", Restaurant Name: " + this.name + " Score: " + score);
System.out.println("Food Items: ");
for (Food f : getAllFoods()) {
f.Displayfood();
}
}
}