You have been asked to produce a report showing the inventory of products at var
ID: 3684045 • Letter: Y
Question
You have been asked to produce a report showing the inventory of products at various warehouses owned by your company using Java. You will need to create three classes: Prog7, Warehouse, and Part. The report will use two files: parts.txt and warehouse.txt with the formats shown below.
warehouse.txt file: text file with the following fields separated by spaces:
Fields
Description
Warehouse ID
3 characters
City
maximum 20 characters
State
2 characters
parts.txt file: CSV (comma separated value) text file in which each line in the file represents a warehouse. The comma delimited fields are:
Fields
Description
Part Number
5 characters
Description
maximum 30 characters
Price
double
Warehouse ID
3 characters
Quantity
Integer, quantity at this warehouse
Using these files, the program will output a summary report listing the parts in each warehouse and the total number of parts in each warehouse. Note that the parts are to be sorted by price. A sample output is as follows:
PGH Pittsburgh, PA
Total Number of Parts: 511
Part# Description Price Quantity
24680 Smoke Shifter 0.98 48
01020 Inflatable Dart Board 32.95 453
00000 Glass Hammer 105.90 8
12345 Left-Handed Bacon Stretcher 125.95 2
ATL Atlanta, GA
Total Number of Parts: 266
Part# Description Price Quantity
86420 Pre-dug Post Hole 2.49 34
25632 Acme Widget 98.29 248
12345 Left-Handed Bacon Stretcher 125.95 15
97531 Anti-Gravity Turbine 895.29 3
When developing a large, multiple-class program, it is advisable to test each class before proceeding. The following sequence is recommended for this assignment:
1. Develop Java classes for Warehouse and Part. Test each class separately to ensure the methods work correctly.
2. Begin the test program by reading each file into an array of the corresponding objects. Display each the contents of each array to verify that the objects are correctly filled in the arrays.
3. Complete the test program named Prog7 by adding the code to produce the report.
The user is not required to provide any input.
Fields
Description
Warehouse ID
3 characters
City
maximum 20 characters
State
2 characters
Explanation / Answer
part.txt
24680,Smoke Shifter,0.98,PGH,48
01020,Inflatable Dart Board,32.95,PGH,453
00000,Glass Hammer,105.90,PGH,8
12345,Left-Handed Bacon Stretcher,125.95,PGH,2
86420,Pre-dug Post Hole,2.49,ATL,34
25632,Acme Widget,98.29,ATL,248
12345,Left-Handed Bacon Stretcher,125.95,ATL,15
97531,Anti-Gravity Turbine,895.29,ATL,3
package com.he.capillary.chegg1;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class WarehousePart {
public static void main(String[] args) throws IOException {
List<Warehouse> warehouseList = new ArrayList<Warehouse>();
Warehouse warehouse = null;
BufferedReader br1 = new BufferedReader(new FileReader("/home/raghunandangupta/mygit/tally/src/main/java/com/he/capillary/chegg1/warehouse.txt"));
String line = br1.readLine();
while (line != null) {
String str[] = line.split(",");
warehouseList.add(new Warehouse(str[0], str[1], str[2]));
line = br1.readLine();
}
BufferedReader br2 = new BufferedReader(new FileReader("/home/raghunandangupta/mygit/tally/src/main/java/com/he/capillary/chegg1/parts.txt"));
line = br2.readLine();
while (line != null) {
String str[] = line.split(",");
warehouse = new Warehouse(str[3], null, null);
if(warehouseList.indexOf(warehouse) != -1){
warehouseList.get(warehouseList.indexOf(warehouse)).getPartList().add(new Part(str[0], str[1], Double.parseDouble(str[2]), str[3], Integer.parseInt(str[4])));
}
line = br2.readLine();
}
StringBuilder sb = new StringBuilder();
if(warehouseList.size() > 0){
for(Warehouse tempWarehouse : warehouseList){
sb.append(tempWarehouse.getWarehouseId()+" "+tempWarehouse.getCity()+", "+tempWarehouse.getState()+" ");
sb.append("Total Number of Parts: "+tempWarehouse.getPartList().size()+" ");
sb.append("Part# Description Price Quantity ");
for(Part part : tempWarehouse.getPartList()){
sb.append(part.getPartNUmber()+" "+part.getDescription()+" "+part.getPrice()+" "+part.getQuantity()+" ");
}
sb.append(" ");
}
}
System.out.println(sb.toString());
}
}
package com.he.capillary.chegg1;
import java.util.ArrayList;
import java.util.List;
public class Warehouse {
private String warehouseId;
private String city;
private String state;
private List<Part> partList = new ArrayList<Part>();
public String getWarehouseId() {
return warehouseId;
}
public void setWarehouseId(String warehouseId) {
this.warehouseId = warehouseId;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Warehouse(String warehouseId, String city, String state) {
super();
this.warehouseId = warehouseId;
this.city = city;
this.state = state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((warehouseId == null) ? 0 : warehouseId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Warehouse other = (Warehouse) obj;
if (warehouseId == null) {
if (other.warehouseId != null)
return false;
} else if (!warehouseId.equals(other.warehouseId))
return false;
return true;
}
public List<Part> getPartList() {
return partList;
}
public void setPartList(List<Part> partList) {
this.partList = partList;
}
}
package com.he.capillary.chegg1;
public class Part {
private String partNUmber;
private String description;
private double price;
private String warehouseId;
private Integer quantity;
public String getPartNUmber() {
return partNUmber;
}
public void setPartNUmber(String partNUmber) {
this.partNUmber = partNUmber;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getWarehouseId() {
return warehouseId;
}
public void setWarehouseId(String warehouseId) {
this.warehouseId = warehouseId;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public Part(String partNUmber, String description, double price, String warehouseId, Integer quantity) {
super();
this.partNUmber = partNUmber;
this.description = description;
this.price = price;
this.warehouseId = warehouseId;
this.quantity = quantity;
}
}
warehouse.txt
PGH,Pittsburgh,PA
ATL,Atlanta,GA
Let me know if you need modification.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.