• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help me debug program

 
Henry Bueno
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Bueno
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What should I use instead?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You.
I got it to work. I really appreciate your help.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic