-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeal.java
More file actions
36 lines (30 loc) · 744 Bytes
/
Meal.java
File metadata and controls
36 lines (30 loc) · 744 Bytes
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
package builder_pattern;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName Meal
* @Description TODO
* @Author qulingxiao
* @Date 2020/7/18 10:46
* @Version 1.0
*/
public class Meal {
public List<Item> items = new ArrayList<Item>();
public void add(Item item){
items.add(item);
}
public float getPrice(){
float cost = 0.0f;
for(Item item: items){
cost+=item.price();
}
return cost;
}
public void showItems(){
for(Item item: items) {
System.out.print("Item : "+item.name());
System.out.print(", Packing : "+item.packing().pack());
System.out.println(", Price : "+item.price());
}
}
}