wood burning stoves
The moose likes Java in General and the fly likes Please Help Me with Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic

Please Help Me with Program

Henry Bueno

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.
* 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}]
//Table.java Class
import java.util.*;
public class Table{
protected ArrayList tableRows; //The List

public Table(){
tableRows = new ArrayList();
public void addRow(TableRow rowIn){

public Iterator iterator() {
return tableRows.Iterator();
public String toString() {
Map mapRef = tableRows;
return mapRef.toString();
//TableRow.java Class
import java.util.*;
public class TableRow{
HashMap data;
public TableRow(){
data = new HashMap();
public void set(String p1, String p2){
public String get(String search)
return data.get(search.toString());
//Exercise1.java Class
import java.util.Iterator;
public class Exercise1 {
public static void main(String[] args) {
Table table = new Table();
//add first row to table
TableRow row = new TableRow();
row.set("firstName", "Mickey");
row.set("lastName", "Mouse");
row.set("phone", "407-555-1212");
row.set("age", "50");
table.addRow( row );
//add second row to table
row.set("firstName", "Donald");
row.set("lastName", "Duck");
row.set("phone", "800-555-1212");
row.set("age", "40");
table.addRow( row );
//display the first name for all rows
Iterator i = table.iterator();
while ( i.hasNext() ) {
row = (TableRow) i.next();
System.out.println( "First Name is: " + row.get("firstName"));
//display the entire table
System.out.println(table.toString() );
Please Help. Thanks.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please do not double post. Respond in Beginner please.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link: http://aspose.com/file-tools
subject: Please Help Me with Program
It's not a secret anymore!