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
package com.restaurant;
public class Order {
private int id;
private Customer customer;
private Food[] foods;
private int price;
public Order(int id, Customer customer, Food[] foods) {
this.id = id;
this.customer = customer;
this.foods = foods;
for (Food food : foods) {
price += food.getPrice();
}
price *= 1.4;
customer.setOrder(this);
}
public Food[] getFoods() {
return foods;
}
public int getPrice() {
return price;
}
public void addFood(Food food, int amount){
Food[] temp = new Food[foods.length + amount];
for (int i = 0; i < foods.length; i++) {
temp[i] = foods[i];
}
for (int i = 0; i < amount; i++) {
temp[foods.length + i] = food;
price += (temp[foods.length + i].getPrice() )* 1.4;
}
foods = temp;
temp = null;
}
public Customer getCustomer() {
return customer;
}
}