Skip to content

Commit a74504a

Browse files
committed
Formatting for readability; worked on Inventory update methods (unsuccessfully)
1 parent 393471e commit a74504a

4 files changed

Lines changed: 58 additions & 18 deletions

File tree

src/main/java/sealey/javafxinventorysystem/models/InHouse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
* The InHouse class inherits attributes from abstract class Part, and adds Machine ID number.
77
* */
88
public class InHouse extends Part {
9+
910
private int machineId;
1011

1112
/*
1213
* InHouse class constructor, called when an InHouse object is created. Assigns initial values.
1314
*/
1415
public InHouse(int id, String name, double price, int stock, int min, int max) {
16+
1517
super(id, name, price, stock, min, max);
1618
this.machineId = getMachineId();
1719
}
@@ -20,13 +22,15 @@ public InHouse(int id, String name, double price, int stock, int min, int max) {
2022
* @return machineId machine id number to get (integer)
2123
* */
2224
public int getMachineId() {
25+
2326
return machineId;
2427
}
2528

2629
/*
2730
* @param machineId ID number to assign
2831
* */
2932
public void setMachineId(int machineId) {
33+
3034
this.machineId = machineId;
3135
}
3236
}

src/main/java/sealey/javafxinventorysystem/models/Inventory.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* */
1313

1414
public class Inventory {
15+
1516
private static ObservableList<Part> allParts = FXCollections.observableArrayList();
1617
private static ObservableList<Product> allProducts = FXCollections.observableArrayList();
1718

@@ -22,6 +23,7 @@ public class Inventory {
2223
* @return allParts List of parts in the inventory
2324
* */
2425
public static ObservableList<Part> getAllParts() {
26+
2527
return allParts;
2628
}
2729

@@ -32,6 +34,7 @@ public static ObservableList<Part> getAllParts() {
3234
* @param allParts List of parts to be stored in the inventory
3335
* */
3436
public static void setAllParts(ObservableList<Part> allParts) {
37+
3538
Inventory.allParts = allParts;
3639
}
3740

@@ -42,6 +45,7 @@ public static void setAllParts(ObservableList<Part> allParts) {
4245
* @return allProducts List of products in the inventory
4346
* */
4447
public static ObservableList<Product> getAllProducts() {
48+
4549
return allProducts;
4650
}
4751

@@ -52,6 +56,7 @@ public static ObservableList<Product> getAllProducts() {
5256
* @param allParts List of parts to be stored in the inventory
5357
* */
5458
public static void setAllProducts(ObservableList<Product> allProducts) {
59+
5560
Inventory.allProducts = allProducts;
5661
}
5762

@@ -61,6 +66,7 @@ public static void setAllProducts(ObservableList<Product> allProducts) {
6166
* @param part Part to be added to list
6267
* */
6368
public static void addPart(Part part) {
69+
6470
allParts.add(part);
6571
}
6672

@@ -70,6 +76,7 @@ public static void addPart(Part part) {
7076
* @param product Product to be added to list
7177
* */
7278
public static void addProduct(Product product) {
79+
7380
allProducts.add(product);
7481
}
7582

@@ -80,6 +87,7 @@ public static void addProduct(Product product) {
8087
* @return a Parts object with matching id number or null (if not found)
8188
* */
8289
public static Part lookupPart(int partID) {
90+
8391
for(Part a : getAllParts()) {
8492
if(a.getId() == partID){ return a; }
8593
}
@@ -93,6 +101,7 @@ public static Part lookupPart(int partID) {
93101
* @return a Product object with matching id number or null (if not found)
94102
* */
95103
public static Product lookupProduct(int prodID) {
104+
96105
for(Product a : getAllProducts()) {
97106
if(a.getId() == prodID){ return a; }
98107
}
@@ -107,6 +116,7 @@ public static Product lookupProduct(int prodID) {
107116
* @return temp List of parts where the search term is contained in the part's name
108117
* */
109118
public static ObservableList<Part> lookupPart(String partName) {
119+
110120
ObservableList<Part> temp = FXCollections.observableArrayList();
111121

112122
for(Part p : Inventory.getAllParts()) {
@@ -126,6 +136,7 @@ public static ObservableList<Part> lookupPart(String partName) {
126136
* @return temp List of products where the search term is contained in the product's name
127137
* */
128138
public static ObservableList<Product> lookupProduct(String productName) {
139+
129140
ObservableList<Product> temp = FXCollections.observableArrayList();
130141

131142
for(Product p : Inventory.getAllProducts()) {
@@ -146,13 +157,23 @@ public static ObservableList<Product> lookupProduct(String productName) {
146157
*
147158
* */
148159
public static void updatePart(Part part) {
149-
for(Part a : getAllParts()) {
150-
if(a.getId() == part.getId()) {
151-
a.setName(part.getName());
152-
a.setPrice(part.getPrice());
153-
a.setStock(part.getStock());
154-
a.setMax(part.getMax());
155-
a.setMin(part.getMin());
160+
161+
for(Part p : Inventory.getAllParts())
162+
{
163+
if(p.getId() == part.getId())
164+
{
165+
if(part instanceof InHouse){
166+
167+
} else {
168+
((OutSourced) p).setCompanyName(((OutSourced) part).getCompanyName());
169+
}
170+
p.setId(part.getId());
171+
p.setName(part.getName());
172+
p.setPrice(part.getPrice());
173+
p.setStock(part.getStock());
174+
p.setMin(part.getMin());
175+
p.setMax(part.getMax());
176+
return;
156177
}
157178
}
158179
}
@@ -166,15 +187,7 @@ public static void updatePart(Part part) {
166187
*
167188
* */
168189
public static void updateProduct(Product product) {
169-
for(Product a : getAllProducts()) {
170-
if(a.getId() == product.getId()) {
171-
a.setName(product.getName());
172-
a.setPrice(product.getPrice());
173-
a.setStock(product.getStock());
174-
a.setMax(product.getMax());
175-
a.setMin(product.getMin());
176-
}
177-
}
190+
178191
}
179192

180193
/*
@@ -184,7 +197,8 @@ public static void updateProduct(Product product) {
184197
* @return boolean True if successful, False if unsuccessful
185198
* */
186199
public static boolean deletePart(Part part) {
187-
return (Boolean)Inventory.getAllParts().remove(part);
200+
201+
return Inventory.getAllParts().remove(part);
188202
}
189203

190204
/*
@@ -194,6 +208,7 @@ public static boolean deletePart(Part part) {
194208
* @return boolean True if successful, False if unsuccessful
195209
* */
196210
public static boolean deleteProduct(Product product) {
197-
return (Boolean)Inventory.getAllProducts().remove(product);
211+
212+
return Inventory.getAllProducts().remove(product);
198213
}
199214
}

src/main/java/sealey/javafxinventorysystem/models/OutSourced.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
* */
88

99
public class OutSourced extends Part {
10+
1011
private String companyName;
1112

1213
/*
1314
* Outsourced class constructor, called when an Outsourced object is created. Assigns initial values.
1415
*/
1516
public OutSourced(int id, String name, double price, int stock, int min, int max) {
17+
1618
super(id, name, price, stock, min, max);
1719
this.companyName = getCompanyName();
1820
}
@@ -21,13 +23,15 @@ public OutSourced(int id, String name, double price, int stock, int min, int max
2123
* @return companyName company name to get (string)
2224
* */
2325
public String getCompanyName() {
26+
2427
return companyName;
2528
}
2629

2730
/*
2831
* @param companyName company name to set (string)
2932
* */
3033
public void setCompanyName(String companyName) {
34+
3135
this.companyName = companyName;
3236
}
3337
}

src/main/java/sealey/javafxinventorysystem/models/Product.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* add a part, delete a part, and retrieve the entire list.
1414
* */
1515
public class Product {
16+
1617
private static ObservableList<Part> associatedParts;
1718
private int id;
1819
private String name;
@@ -25,6 +26,7 @@ public class Product {
2526
* Product class constructor, called when a Product object is created. Assigns initial values.
2627
* */
2728
public Product(int id, String name, double price, int stock, int min, int max) {
29+
2830
this.id = id;
2931
this.name = name;
3032
this.price = price;
@@ -37,90 +39,103 @@ public Product(int id, String name, double price, int stock, int min, int max) {
3739
* @return id the id to get
3840
*/
3941
public int getId() {
42+
4043
return id;
4144
}
4245

4346
/**
4447
* @param id the id to set
4548
*/
4649
public void setId(int id) {
50+
4751
this.id = id;
4852
}
4953

5054
/**
5155
* @return name the name to get
5256
*/
5357
public String getName() {
58+
5459
return name;
5560
}
5661

5762
/**
5863
* @param name the name to set
5964
*/
6065
public void setName(String name) {
66+
6167
this.name = name;
6268
}
6369

6470
/**
6571
* @return price the price to get
6672
*/
6773
public double getPrice() {
74+
6875
return price;
6976
}
7077

7178
/**
7279
* @param price the price to set
7380
*/
7481
public void setPrice(double price) {
82+
7583
this.price = price;
7684
}
7785

7886
/**
7987
* @return stock the stock to get
8088
*/
8189
public int getStock() {
90+
8291
return stock;
8392
}
8493

8594
/**
8695
* @param stock the stock to set
8796
*/
8897
public void setStock(int stock) {
98+
8999
this.stock = stock;
90100
}
91101

92102
/**
93103
* @return min the min to get
94104
*/
95105
public int getMin() {
106+
96107
return min;
97108
}
98109

99110
/**
100111
* @param min the min to set
101112
*/
102113
public void setMin(int min) {
114+
103115
this.min = min;
104116
}
105117

106118
/**
107119
* @return max the max to get
108120
*/
109121
public int getMax() {
122+
110123
return max;
111124
}
112125

113126
/**
114127
* @param max the max to set
115128
*/
116129
public void setMax(int max) {
130+
117131
this.max = max;
118132
}
119133

120134
/*
121135
* @return associatedParts The entire list of parts associated with the product
122136
* */
123137
public static ObservableList<Part> getAllAssociatedParts() {
138+
124139
return associatedParts;
125140
}
126141

@@ -130,6 +145,7 @@ public static ObservableList<Part> getAllAssociatedParts() {
130145
* @param part Part object to be added to list
131146
* */
132147
public static void addAssociatedPart(Part part) {
148+
133149
associatedParts.add(part);
134150
}
135151

@@ -141,6 +157,7 @@ public static void addAssociatedPart(Part part) {
141157
* @return boolean True if successful, False if unsuccessful
142158
* */
143159
public static boolean deleteAssociatedPart(Part selectedAssociatedPart) {
160+
144161
return (Boolean)associatedParts.remove(selectedAssociatedPart);
145162
}
146163
}

0 commit comments

Comments
 (0)