aspose file tools*
The moose likes Beginning Java and the fly likes Panel program(help plzzzzzzzzzz) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Panel program(help plzzzzzzzzzz)" Watch "Panel program(help plzzzzzzzzzz)" New topic
Author

Panel program(help plzzzzzzzzzz)

prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
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

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

I don't see any reference in your code where you actually open and read from the "Inventory.txt" file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
I did not get it. Can anybody plzzzzzzzzzzz expalin where I am wrong.
Thanks
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

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

Joined: Aug 19, 2004
Posts: 67
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Take a look at your code again...



Does it look right?

Henry
[ May 11, 2005: Message edited by: Henry Wong ]
prerna boja
Ranch Hand

Joined: Aug 19, 2004
Posts: 67
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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

Joined: Aug 19, 2004
Posts: 67
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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

Joined: Aug 19, 2004
Posts: 67
yes that is what I want to do.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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

Joined: Aug 19, 2004
Posts: 67
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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

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
 
 
subject: Panel program(help plzzzzzzzzzz)