-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
49 lines (35 loc) · 746 Bytes
/
Order.java
File metadata and controls
49 lines (35 loc) · 746 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
37
38
39
40
41
42
43
44
45
46
47
48
49
package assignment6;
import java.util.ArrayList;
import java.util.Iterator;
/**
* An order class. It is a composite of Payable objects, such that
*
* @author Rían Adamian
* @since 13/11/2018
*/
public class Order implements Payable {
private ArrayList<Item> order;
public Order() {
order = new ArrayList<Item>();
}
public void add(Item i) {
order.add(i);
}
@Override
public double getPrice() {
double total = 0.0;
for (Payable p: order) {
total += p.getPrice();
}
return total;
}
@Override
public String toString() {
Iterator<Item> iterator = order.iterator();
String s = "";
while (iterator.hasNext() == true) {
s += iterator.next().toString() + "\n";
}
return s;
}
}