-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPremiumAccount.java
More file actions
56 lines (46 loc) · 1.69 KB
/
PremiumAccount.java
File metadata and controls
56 lines (46 loc) · 1.69 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
package shopping;
import java.util.ArrayList;
import java.util.List;
public class PremiumAccount extends Account {
private ArrayList<Product> products;
public PremiumAccount(int object_id, String accountId, String billingAddress, int balance) {
super(object_id, accountId, billingAddress,balance);
products = new ArrayList<Product>();
}
public void addProduct(Product product, int quantity, int price){
product.setPrice(price);
product.setInStock(quantity);
products.add(product);
}
public ArrayList<Product> getProducts() {
return products;
}
@Override
public String toString() {
String fields = "Account, id:" + accountId + ", Billing Address:" + billingAddress + ", Is Closed:" + isClosed + ", Opened:" + open
+ ", Closed:" + closed + ", Balance:" + balance + "\n";
String connected = "Connected to:" + customer.getClass().getSimpleName() + ", " + shoppingCart.getClass().getSimpleName();
if (orders.size() > 0){
String ords = "";
for (Order o : orders){
ords += o.getClass().getSimpleName() + ",";
}
connected += ", " + ords;
}
if (payments.size() > 0){
String pays = "";
for (Payment p : payments){
pays += p.getClass().getSimpleName() + ",";
}
connected += ", " + pays;
}
if (products.size() > 0){
String prod = "";
for (Product p : products){
prod += p.getClass().getSimpleName() + ",";
}
connected += ", " + prod;
}
return fields + connected;
}
}