aspose file tools*
The moose likes Beginning Java and the fly likes Please Help me debug program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please Help me debug program" Watch "Please Help me debug program" New topic
Author

Please Help me debug program

Henry Bueno
Greenhorn

Joined: Apr 03, 2003
Posts: 8
Task Description:
Use notepad or textpad to implement two classes(Table & TableRow)to support the code listed below titled Exercise1.java. Compile your classes and then compile Exercise1.java. Test and run.
Hints:
* Consider using Java collection classes to implement Table and TableRow.
Expected Output:
First Name is : Mickey
First Name is : Donald
Table with 2 rows [{phone=407-555-1212, age=50, lastName=Mouse, firstName=Mickey}{phone=800-555-1212, age=40, lastName=Duck, firstName=Donald}]

------------------------------------------
------------------------------------------
Please Help. Thanks.
[ April 03, 2003: Message edited by: Thomas Paul ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
This line is invalid:
Map mapRef = tableRows;
because tableRows is an ArrayList. An ArrayList can't be stored in a Map variable.
This line is invalid:
return data.get(search.toString());
data.get() returns an Object but the method declaration says you are returning a String.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Henry Bueno
Greenhorn

Joined: Apr 03, 2003
Posts: 8
What should I use instead?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The toString() method of the Table class has to be custom written to produce the output you want.
The data.get returns an Object but you know that it is really a String so what do you need to do to tell the compiler that the result is a String? Maybe casting?
The put() method of TableRow is reversing the input params.
If you place a TableRow in the ArrayList and then make a change to TableRow you are changing the TableRow in the ArrayList. You need to create a new TableRow each time before you add it to the ArrayList.
Henry Bueno
Greenhorn

Joined: Apr 03, 2003
Posts: 8
Thank You.
I got it to work. I really appreciate your help.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
My pleasure!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help me debug program