I have some .txt files, which I read in to build two objects.
Item, with fields:
Description|SKU|Retail Price|Discount
and Store with fields:
ID|Description|Street|City|Province|Postal Code|Store Phone|Auto Service
I have another .txt file for the Inventory object, which is a bridge entity which ties them together. Inventory’s fields are:
Store ID|Item SKU|Item Count
Obviously, those come from the Item and Store classes.
Here is my objective:
I want to create an inventory report which synthesizes the three lists into a single console printed output, but am hitting a wall about how to get there.
This is about as far as I got:
public static void write(List<Item> items, List<Store> stores, List<Stock> stocks) {
System.out.println();
System.out.println("Inventory Report");
System.out.println("----------------");
for (Item it : items) {
for (Stock s : stocks) {
if(it.getProductNumber() == s.getItemSKU()) {
for (Store st: stores) {
if(st.getId() == s.getStoreID()) {
System.out.println(it.getDescription() + "is from store" + st.getId() + "in" + st.getCity() + "and costs" + it.getPrice());
}
}
}
}
}
}
I know that the obvious solution should be creating tables and putting the info in, but this is an assignment that says that I should do it using pure java…
I am probably close, but my logic is off here… How best could one cross reference two Classes based on the third class?
Help would be much appreciated.
Store your Items and Stores in Maps, where their Id is the key:
Pass them to your output method and it is easy as cake:
EDIT:Had little errors in the lines with a comment, fixed it.