-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCraftsShop.java
More file actions
134 lines (118 loc) · 3.68 KB
/
Copy pathCraftsShop.java
File metadata and controls
134 lines (118 loc) · 3.68 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
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
import java.util.Iterator;
import java.util.Enumeration;
import java.util.ArrayList;
public class CraftsShop{
// The new line separator:
private final String NL = System.getProperty("line.separator");
/**
* This atribute stores the list of materials
*/
private ArrayList<Material> materials;
/**
* This atribute stores the list of products
*/
private ArrayList<Product> products;
/**
* This atribute stores the list of orders
*/
private ArrayList<Order> orders;
/**
* Constructor method
*/
public CraftsShop() {
this.materials = new ArrayList<Material>();
this.products = new ArrayList<Product>();
this.orders = new ArrayList<Order>();
}
/**
* This method adds an element to the list of materials
* @param m
*/
public void add(Material m) {
this.materials.add(m);
}
/**
* This method adds an element to the list of products
* @param p
*/
public void add(Product p) {
this.products.add(p);
}
/**
* This method adds an element to the list of orders
* @param o
*/
public void add(Order o) {
this.orders.add(o);
}
/**
* This method generates and returns the information of
* every element in the materials list of the shop, in
* the order they were introduced.
*/
public String listOfMaterials() {
StringBuilder sb = new StringBuilder();
for (Iterator<Material> it = materials.iterator(); it.hasNext();) {
Material m = (Material) it.next();
sb.append(m.toString());
}
return sb.toString();
}
/**
* This method generates and returns the information of
* every element in the products list of the shop, in
* the order they were introduced.
*/
public String listOfProducts() {
StringBuilder sb = new StringBuilder();
for (Iterator<Product> it = products.iterator(); it.hasNext();) {
Product p = (Product) it.next();
sb.append(p.toString() + NL);
}
return sb.toString();
}
/**
* This method generates and returns the information of
* every element in the orders list of the shop, in
* the order they were introduced.
*/
public String listOfOrders() {
StringBuilder sb = new StringBuilder();
for (Iterator<Order> it = orders.iterator(); it.hasNext();) {
Order o = (Order) it.next();
sb.append(o.toString() + NL);
}
return sb.toString();
}
/**
* This method generates and returns the information of
* those elements in the products list of the shop,
* whose price is comprised between a minimum and a maximum
* values (both included).
* @param min
* minimum price
* @param max
* maximum price
*/
public String listProductsInPriceRange(double min, double max) {
StringBuilder sb = new StringBuilder();
for (Iterator<Product> it = products.iterator(); it.hasNext();) {
Product p = (Product) it.next();
if ((p.price()>=min)&&(p.price()<=max))
sb.append(p.toString() + NL);
}
return sb.toString();
}
/**
* This method removes an Order object from the list orders.
* To do its task, this method has to use the appropriate
* method of ArrayList class.
* And to do that, it is necessary to redefine the equals
* method on class Order, to define whether two Order
* objects are equals (see description of equals method in
* class Order)
*/
public boolean removeOrder(Order order) {
return this.orders.remove(order);
}
}