Repository navigation
Expand file tree
/
Copy pathProduct.java
More file actions
144 lines (133 loc) · 4.62 KB
/
Copy pathProduct.java
File metadata and controls
144 lines (133 loc) · 4.62 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
135
136
137
138
139
140
141
142
143
144
/**
* Project 5 - Product.java
*
* Class that represents an individual product available in a seller's store.
*
* @author Shafer Anthony Hofmann, Qihang Gan, Shreyas Viswanathan, Nathan Pasic
* Miller, Oliver Long
*
* @version December 6, 2023
*/
public class Product {
private Database db = new Database();
private String productIdentificationNumber;
private String name;
private int availableQuantity;
private double price;
private String description;
private int orderLimit;
private String reviews;
private int saleQuantity;
private double salePrice;
/**
* Creating a new product for the first time. Generates a unique ID and adds a
* signifier to it indicating that it is a product.
*
* @param name The new product's name
* @param availableQuantity The new product's quantity
* @param price The new product's price
* @param description The new product's description
*/
public Product(String name, int availableQuantity, double price, String description, int orderLimit, int saleQuantity, double salePrice) {
this.productIdentificationNumber = "PR" + String.valueOf(generateProductIdentificationNumber());
this.name = name;
this.availableQuantity = availableQuantity;
this.price = price;
this.description = description;
this.orderLimit = orderLimit; // Maybe make this optional later
this.reviews = "[]";
// Optional: If the seller doesn't wish to hold a sale, they must enter 0 for both fields
this.saleQuantity = saleQuantity;
this.salePrice = salePrice;
}
/**
* Re-initializing an already existing product.
*
* @param productIdentificationNumber The existing product's ID
* @param name The existing product's name
* @param availableQuantity The existing product's quantity
* @param price The existing product's price
* @param description The existing product's description
*/
public Product(String productIdentificationNumber, String name, int availableQuantity, double price,
String description, int orderLimit, String reviews, int saleQuantity, double salePrice) {
this.productIdentificationNumber = productIdentificationNumber;
this.name = name;
this.availableQuantity = availableQuantity;
this.price = price;
this.description = description;
this.orderLimit = orderLimit;
this.reviews = reviews;
this.saleQuantity = saleQuantity;
this.salePrice = salePrice;
}
/**
* Gets the current product's ID
*
* @return The ID associated with this product
*/
public String getProductIdentificationNumber() {
return this.productIdentificationNumber;
}
/**
* Gets the current product's name
*
* @return The name associated with this product
*/
public String getName() {
return this.name;
}
/**
* Gets the current product's description
*
* @return The description associated with this product
*/
public String getDescription() {
return this.description;
}
/**
* Gets the current product's quantity
*
* @return The quantity associated with this product
*/
public int getAvailableQuantity() {
return this.availableQuantity;
}
/**
* Gets the current product's price
*
* @return The price associated with this product
*/
public double getPrice() {
return this.price;
}
/**
* Gets the current product's order limit
*
* @return The order limit associated with this product
*/
public int getOrderLimit() {
return this.orderLimit;
}
/**
* Returns a string representation of the current product. Utilized in the
* stores.csv database.
*/
@Override
public String toString() {
return String.format("%s,%d,%.2f,%s,%d,%s,%d,%.2f", this.name, this.availableQuantity, this.price, this.description, this.orderLimit, this.reviews, this.saleQuantity, this.salePrice);
}
/**
* Returns a unique 7-digit ID as long as the current ID is not already
* associated with an existing account in the products.csv database
*
* @return A unique 7-digit ID
*/
public int generateProductIdentificationNumber() {
int currentID = 1000000; // The first store created will have this ID
while (db.checkIDMatch(currentID, "products.csv")) {
currentID += 1;
}
return currentID;
}
}