In my opinion my issue is around line 76->105 and 135-> 167 at order class. Issue about saveTofile and loadfromFile. I try to print the file a class tester2 line 24 o1.loadFromFile("Order1.or") but it didn't work it just work for line 28->41 at class tester2. i tried a lot of different methods but it just work for "SaveTest2.or" not work for "Order1.or".
An observation: you have to lists: productId and quantity, that you are trying to keep in sync. I suggest creating an "Item" class that holds one productId and one quantity and then treat that as a single Item entry for reading and writing.
Carey Brown wrote:An observation: you have to lists: productId and quantity, that you are trying to keep in sync. I suggest creating an "Item" class that holds one productId and one quantity and then treat that as a single Item entry for reading and writing.
It looks like an assignment which has been supplied with a pair of lists so the OP probably isn't allowed to change what you have correctly pointed out is an awful design.
Your save method writes out each product id and then writes out each qty, you should be writing out one product id followed by a comma followed by a qty and then a new line character and repeat this for each product id/qty pair.
Choosing more descriptive variable names would improve your code readability, because: id, qty, theP, theQ, p1, o1, o2, p2 are as hell confusing.
Starting to improve your code from such a small but powerful things could point you towards solution.
According to your issue (which is still not clear for me), have you tried to check with debugger during the output on 5th line whats happening? Is it your main issue that you do not get expected value?
Liutauras Vilda wrote:Choosing more descriptive variable names would improve your code readability, because: id, qty, theP, theQ, p1, o1, o2, p2 are as hell confusing.
Starting to improve your code from such a small but powerful things could point you towards solution.
According to your issue (which is still not clear for me), have you tried to check with debugger during the output on 5th line whats happening? Is it your main issue that you do not get expected value?
Thanks for advise.
After I use debugger I saw that when run
It goes Scanner in = new Scanner(file); -> while(in.hasNextLine()) -> in.close();. It didn't go to anything inside
to load the file from loadFromFile.
So I'm working on it. Could you please give me a hint about it.
Take a step back from the computer, and figure out your algorithm on a piece of paper.
Its amazing how much that helps sometimes.
If I understand right, what you are trying to accomplish is print a list of product and quantity pairs each on their own line.
So it should be something like
Hint:
You effectively have "parallel arrays".
product.get(1) in the product list is associated with quantity.get(1) in the quantity list.
you only need ONE for loop to go through both lists