-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
152 lines (120 loc) · 4.76 KB
/
Copy pathProduct.java
File metadata and controls
152 lines (120 loc) · 4.76 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
145
146
147
148
149
150
151
152
package Model;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Product {
private ObservableList<Part> associatedParts = FXCollections.observableArrayList();
private final IntegerProperty productID;
private final StringProperty name;
private final DoubleProperty price;
private final IntegerProperty inStock;
private final IntegerProperty min;
private final IntegerProperty max;
//have the constructor set the class variables with new simple integer properties.
public Product() {
productID = new SimpleIntegerProperty();
name = new SimpleStringProperty();
price = new SimpleDoubleProperty();
inStock = new SimpleIntegerProperty();
min = new SimpleIntegerProperty();
max = new SimpleIntegerProperty();
}
///return the product ID
//helper function to return an integer property when needed instead of simple integer property
public IntegerProperty getProductIDIntegerProperty() {
return productID;
}
//return the name fo the object
//helper function to return an integer property when needed instead of simple integer property
public StringProperty getProductNameStringProperty() {
return name;
}
//return the price of the object
//helper function to return an integer property when needed instead of simple integer property
public DoubleProperty getProductPriceDoubleProperty() {
return price;
}
//return the number of inventory of the object
//helper function to return an integer property when needed instead of simple integer property
public IntegerProperty getProductInvIntegerProperty() {
return inStock;
}
//get the prodcut ID of the product object
public int getProductID() {
return this.productID.get();
}
//set the prodcut ID of the product object
public void setProductID(int productID) {
this.productID.set(productID);
}
//get the name of the oproduct object
public String getNameProduct() {
return this.name.get();
}
//set the name of the product object
public void setNameProduct(String name) {
this.name.set(name);
}
//get the price of the product object
public double getPriceProduct() {
return this.price.get();
}
//set the price of the product
public void setPriceProduct(double price) {
this.price.set(price);
}
//get the stock of the prodccut
public int getInStockProduct() {
return this.inStock.get();
}
//set the number of stock of produt
public void setInStockProduct(int inStock) {
this.inStock.set(inStock);
}
//get the minimum amount of the product
public int getMinProduct() {
return this.min.get();
}
//set the minimum of the product
public void setMinProduct(int min) {
this.min.set(min);
}
//get the maximum of the product
public int getMaxProduct() {
return this.max.get();
}
//set the maximum of the product
public void setMaxProduct(int max) {
this.max.set(max);
}
//return an observable list of all the parts associated with a product
public ObservableList getProductParts() {
return associatedParts;
}
//add parts that are to be associated with the product
public void addAssociatedParts(ObservableList<Part> parts) {
this.associatedParts = parts;
}
//check if the sum of the parts is greater than the cost of the product
//exception control set 1 applies to product as well because it has a minimum and a maximum
public static String exceptionControlSet2(ObservableList<Part> parts, double price, String min, String max) {
String messageToUser = "";
double sumParts = 0.00;
for (int i = 0; i < parts.size(); i++) {
sumParts = sumParts + parts.get(i).getPricePart();
}
if (sumParts > price) {
messageToUser = "The price of the product has to be greater than the sum of each part";
return messageToUser;
}
if (Integer.parseInt(min) > Integer.parseInt(max)) {
messageToUser = messageToUser + ("Max must be greater than the min value.");
}
return messageToUser;
}
}