Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:40:39+00:00 2026-06-13T19:40:39+00:00

I have some .txt files, which I read in to build two objects. Item,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:40:41+00:00Added an answer on June 13, 2026 at 7:40 pm

    Store your Items and Stores in Maps, where their Id is the key:

        Map<Integer, Item> items = new HashMap<Integer, Item>();
        Map<Integer, Store> stores = new HashMap<Integer, Store>();
    

    Pass them to your output method and it is easy as cake:

    EDIT:Had little errors in the lines with a comment, fixed it.

    public static void write(Map<Integer, Item> items, Map<Integer, Store> stores, List<Stock> stocks) {
        System.out.println();
        System.out.println("Inventory Report");
        System.out.println("----------------");
    
        for(Stock stock : stocks) { // <-- for all Stocks
            Store store = stores.get(stock.getStoreID()); // <-- get Store
            Item item = items.get(stock.getItemSKU());  // <-- get Item
            System.out.println(item.getDescription() + "is from store" + store.getId() + "in" + store.getCity()  + "and costs" + item.getPrice());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data in simplejson format in txt files, which I read using:
i have some files located in c:\MyApp\file.txt and current executing assenbly in in debud
I have some files across several folders: /home/d/folder1/a.txt /home/d/folder1/b.txt /home/d/folder1/c.mov /home/d/folder2/a.txt /home/d/folder2/d.mov /home/d/folder2/folder3/f.txt How
I have a .txt file having some text. I want to read this file
I have some text files which I am trying to transform with a Perl
I have some .gz compressed files which is around 5-7gig uncompressed. These are flatfiles.
I have developed a windows application, which will read updated data from .jrn files(In
I'm doing some relatively simple I/O in Java. I have a .txt files that
I have an app for iOS that display some files in a tableview which
I have some status text displayed in a BASH script, e.g.: Removed file sandwich.txt.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.