• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with output

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have problem with my output can someone give me a hint.
I got for 2nd order but not work for 1st
thank you





 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could you be more precise?
Maybe specify the line numbers, where do you think you face an issue.
 
Yama Kenji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Thank you for reply.

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".

file from Order1.or is:

113489,11
201934,22
3488,12
84432,3
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Yama Kenji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the hint.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your loading from file method also feels wrong to me.
There is a lot of repeated/duplicated code within it. Do you really need all that?


 
Yama Kenji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. You right. I just test again and i realize i just need to use 1 in.useDelimiter(", *");.

I try to do at my public void saveToFile(String filename) at my order class. But i have no idea how to deal with comma at file "Order1.or".

file "Order1.or"


113489,11
201934,22
3488,12
84432,3

I try to follow what Tony Docherty said

for(int theP: productId)
{
String strP = Integer.toString(theP);
String strC = ",";
for(int theQ: quantity)
{
String strQ = Integer.toString(theQ);
print.println(strP+strC+strQ);
}

}

but it didn't. So right now I try to find another way to figure it out.
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Yama Kenji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic