• 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

Panel program(help plzzzzzzzzzz)

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have to build an interactive program that reads in the information about the Inventory objects from the file Inventory.txt into an array of Inventory objects.

I complied my Inventory.java program,it is working fine. I am not able to read the data from Inventory.txt to the FinalExam class.

For example if I type the product code as 1178,and press lookup button then the price(prints 4.52), QuantityOnHand(prints 10) and status(found) should be dispalyed on the frame.

Help me out. I am trying this out from 2 days.

My Inventory.txt :
1178,4.52,10
1295,1.75,30
1299,14.82,20
1384,9.82,50
1471,2.50,100
1502,3.82,60
1532,9.87,15

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any reference in your code where you actually open and read from the "Inventory.txt" file.

Henry
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not get it. Can anybody plzzzzzzzzzzz expalin where I am wrong.
Thanks
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prerna boja:
I did not get it. Can anybody plzzzzzzzzzzz expalin where I am wrong.
Thanks



You aren't wrong, exactly. How do you expect a program to do something that you didn't tell it to do? So do you know how to open a file and read its contents? If not, you should figure that out first. Perhaps you can try and make a separate program that just reads the input file and prints the contents to the screen.

Layne
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prerna boja:
I did not get it. Can anybody plzzzzzzzzzzz expalin where I am wrong.
Thanks



Can you please just use the word "please"?
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,


I rectified my problem, But still I am not able to get the price n quantity on hand to the textfield. I get only status as "Item not found".i.e only else loop is executing.
but my if(found) loop is not exectuting.Why is it so?

Help me out.


 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at your code again...



Does it look right?

Henry
[ May 11, 2005: Message edited by: Henry Wong ]
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is correct. What is wrong with the code I have to scheck whether the stringline is null or not.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prerna boja:
I think it is correct. What is wrong with the code I have to scheck whether the stringline is null or not.



Try again. It is very simple. Pretend you are the computer, and follow the instructions. It should take you less than a minute to figure out.

Henry
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ,

I tried it out. There is nothing worng in that code. I am held up at if(found) loop. I am getting confused ,the more I try to rectify the code.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prerna boja:
Hey ,

I tried it out. There is nothing worng in that code. I am held up at if(found) loop. I am getting confused ,the more I try to rectify the code.



Okay, I'll be the computer...

* Read a line from the file... okay, done
* Is the line null? ... no?... okay, skip the if block
* close the file... okay, done

Is this really what you want done?

Henry
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes that is what I want to do.

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by prerna boja:
yes that is what I want to do.



You want to open a file, read a single line, close the file, and do nothing with the single line?

Henry
 
prerna boja
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I corrected few of my mistakes.

Like :1)when read in file, I should not have a semicolon after the (loop test); (corrected as while(right >= left && !found) )

2) My invArray declaration.(corrected as rivate static Inventory invArray[] = new Inventory[7]; ) as Invenotry.txt is :
1178,4.52,10
1295,1.75,30
1299,14.82,20
1384,9.82,50
1471,2.50,100
1502,3.82,60
1532,9.87,15


3) Binary search :


4)acctually I did not drop the curly bracelet in the correct position, make the while loop not work,then data can not be read in.



I corrected all the above but still my program is not working.

Can anybody please check my Binary serach n point 4,Whether they are correct or not.Please let me know where in the program I am wrong.

Please help me out.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still have a couple of problems with the code that reads in the data file... but I am not willing to go through 3 more rounds trying to convince you... ... so I'll just jump to the answer.

- You throw away the first line from the file. Remember that the first line of the file was read prior to entering the "while" loop. You don't do anything with that line.

- You set a null string into your array. You set the index immediately after the read, without checking the value prior to storing it into the array. And since you throw away the first line, the null value will actually store without getting an out of bounds exception.

Henry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic