Hello everyone. I am stuck on a piece of logic and can't seem to get past it. To be clear, I am not asking for you to do this for me, but I would greatly appreciate it if you could point me in the right direction. First, here is the assignment:
Develop an application that will read and process customer history order
information from a file. Each record of the text file contains a customer ID,
order number, and total of order. An example book order file:
The file can contain several entries for the same customer ID. Your
application should accumulate the total spent for each customer as you read
the order information from the file. The application should print total spent
for each customer.
Refer to Collections in the Sun Java API Documentation. Determine which
Collection implementation would be the best choice for your application.
My problem is trying to figure out the logic. I just can't seem to wrap my head around how to compare customer ID's as I Iterate through the Set or Array and add their orders together for the same customer, but retain their order ID's. Again, if you could point me in the right direction, I would be eternally grateful. I have been chewing on this for a while now.
Now what do you intend to finish with? Do you want 10051 and a record of all his orders put together? Write down what the data will look like when you put them all together. Erase it and start again, and repeat until you are happy with what you have got.
Look at the diagram now. Can you see any pairings or combinations which you can create objects to encapsulate? Can you see any way of creating a Customer object? Add more orders for 10051, and see what your diagram looks like now.
Go to the Java™ Tutorials, and read through all the well-known interfaces in the Collections Framework. Draw a diagram for what each interface in the framework looks like. See whether you can see any analogies to your first diagram.
One hint , create a new POJO class CustomerOrder and include following attributes in it
private double customerID;
private double orderNumber;
private double orderCost;
Thank you for your suggestions! I appreciate it.
Sorry, but what is a POJO class?
Campbell Ritchie wrote:
Not convinced that is the best way to do it, I am afraid.
It is better than three arrays in parallel, however. That is quite error-prone.
This is exactly what I am trying to avoid. I know there is a better way...I have seen it through my studies, but I have a severe case of writers block. Either way, I plan on looking into each of your suggestions more in depth! Thanks a ton!
POJO is a "plain old Java object"...or something like that. I believe the idea is you don't need any fancy, uber-powerful third party class/library....you just write a simple class that has/does what you need.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors