-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
85 lines (74 loc) · 2.35 KB
/
Copy pathProduct.java
File metadata and controls
85 lines (74 loc) · 2.35 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
import java.util.*;
import java.io.*;
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
//private String supplier; // There could be more than one supplier, so we'll have to connect them in a different operation
private double price;
private int quantity; // Quantity available
private List<WaitlistItem> waitlist; // List of WaitlistItems (Product-Client-Quantity pairings)
private List<Pair> catalog;
public Product(String name, int quantity, double price) {
this.name = name;
this.quantity = quantity;
this.price = price;
this.waitlist = new LinkedList<WaitlistItem>();
this.catalog = new LinkedList<Pair>();
}
public String getName() {
return name;
}
public int getQuantity() { // Quantity available
return quantity;
}
public double getPrice() {
return price;
}
public void getCatalog() {
Iterator<Pair> cat = catalog.iterator();
// search for supplier by name
// (iterate until supplier.name == name)
while (cat.hasNext()) {
Pair thispair = cat.next();
System.out.println(thispair.toString());
}
}
public void setName(String name) {
this.name = name;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public void addQuantity(int quantity) {
this.quantity += quantity;
}
public void insertSupplier(Supplier supp, double price) {
Pair newpair = new Pair(supp, this, price);
catalog.add(newpair);
}
public void setPrice(double price) {
this.price = price;
}
public boolean equals(String name) {
return this.name.equals(name);
}
public String toString() {
return "name: " + name + " | quantity available: " + quantity + " | price: " + price;
}
public String suppliersToString() {
return "name: " + name + " | quantity available: " + quantity;
}
// Wait list
public boolean addToWaitlist(WaitlistItem waitlistItem) {
waitlist.add(waitlistItem);
return true; // if successful
}
public Iterator<WaitlistItem> getWaitlistItems() {
if (waitlist.isEmpty()) {
//System.out.println("There are no items on the waitlist for product: " + this.name);
return null;
} else {
return waitlist.iterator();
}
}
}