help with linked lists and searching

Hi guys I'm very new to java. I'm having a problem with linked lists. the program's driver needs to create game objects, store them, be able to search the linked list etc. etc. I've read the API but I am really having trouble understanding it.

First problem is that when I make a new game object through the menu when running the program, and then print the entire schedule all the objects print out the same as the latest game object created

Second problem is searching it. I just really have no idea.

Here is the driver:

import java.util.*;

publicclass teamSchedule

{

publicstaticvoid main (String[]args)

{

//variables

boolean start;

game game1;

int selector;

Scanner scanner1;

String date =new String();

String venue =new String();

String time =new String();

String dateSearch =new String();

double price;

String opponent =new String();

int addindex;

List teamSchedLL =new LinkedList();

String dateIndex =new String();

String removeYN =new String();

String venueIndex =new String();

String opponentIndex =new String();

start =true;//start makes the menu run in a while loop.

while (start ==true)

{

System.out.println("Welcome to the Team Scheduling Program.");

System.out.println("To add a game to the schedule enter 1");

System.out.println("To search for a game by date enter 2");

System.out.println("To search for a game by venue enter 3");

System.out.println("To search for a game by opponent enter 4");

System.out.println("To display all tour information enter 5");

System.out.println("");

System.out.println("To remove a game from the schedule enter search for the game, then"

+" remove it.");

System.out.println("");

System.out.println("Enter choice now:");

scanner1 =new Scanner (System.in);

selector = scanner1.nextInt();

System.out.println("");

if (selector == 1)

{

//add a game

scanner1.nextLine();

System.out.println("Adding a game...");

System.out.println("Enter game date:");

date = scanner1.nextLine();

System.out.println("Enter game venue:");

venue = scanner1.nextLine();

System.out.println("Enter game time:");

time = scanner1.nextLine();

System.out.println("Enter ticket price:");

price = scanner1.nextDouble();

scanner1.nextLine();

System.out.println("Enter opponent:");

opponent = scanner1.nextLine();

game1 =new game(date, venue, time, price, opponent);

teamSchedLL.add(game1);

System.out.println(teamSchedLL);

System.out.println("Game created, returning to main menu. \n");

start =true;

}

elseif (selector == 2)

{

//search using date

scanner1.nextLine();

System.out.println("Enter the date to search for in the format that it was entered:");

dateIndex = scanner1.nextLine();

if (teamSchedLL.indexOf(dateIndex) == -1)

{

System.out.println("No matching date found. Returning to main menu.");

start =true;

}

else

{

//give user option to remove game if they wish.

System.out.println(teamSchedLL.get(teamSchedLL.indexOf(dateIndex)));

System.out.println("Would you like to remove this game? Y/N");

removeYN = scanner1.nextLine();

if (removeYN =="Y" || removeYN =="y")

{

teamSchedLL.remove(teamSchedLL.indexOf(dateIndex));

System.out.println("Scheduled game removed.");

}

}

System.out.println("\n Returning to main menu. \n");

start =true;

}

elseif (selector == 3)

{

//search using venue name

scanner1.nextLine();

System.out.println("Enter the venue to search for in the format that it was entered:");

venueIndex = scanner1.nextLine();

if (teamSchedLL.indexOf(venueIndex) == -1)

{

System.out.println("No matching venue found. Returning to main menu.");

start =true;

}

else

{

//give user option to remove game

System.out.println(teamSchedLL.get(teamSchedLL.indexOf(venueIndex)));

System.out.println("Would you like to remove this game? Y/N");

removeYN = scanner1.nextLine();

if (removeYN =="Y" || removeYN =="y")

{

teamSchedLL.remove(teamSchedLL.indexOf(venueIndex));

System.out.println("Scheduled game removed.");

}

}

System.out.println("\n Returning to main menu. \n");

start =true;

}

elseif (selector == 4)

{

//search using opponent name

scanner1.nextLine();

System.out.println("Enter the opponent to search for in the format that it was entered:");

opponentIndex = scanner1.nextLine();

if (teamSchedLL.indexOf(opponentIndex) == -1)

{

System.out.println("No matching opponent found. Returning to main menu.");

start =true;

}

else

{

//give user option to remove game

System.out.println(teamSchedLL.get(teamSchedLL.indexOf(opponentIndex)));

System.out.println("Would you like to remove this game? Y/N");

removeYN = scanner1.nextLine();

if (removeYN =="Y" || removeYN =="y")

{

teamSchedLL.remove(teamSchedLL.indexOf(opponentIndex));

System.out.println("Scheduled game removed.");

}

}

System.out.println("\n Returning to main menu. \n");

start =true;

}

elseif (selector == 5)

{

//display tour info

System.out.println("Tour Schedule:");

System.out.println(teamSchedLL +"\n");

}

else

{

System.out.println("Incorrect choice entered. Returning to menu");

System.out.println("");

System.out.println("");

System.out.println("");

}

}

}

}

__

and here is the game class:

publicclass game

{

privatestatic String gameDate;

privatestatic String gameVenue;

privatestatic String gameTime;

privatestaticdouble gamePrice;

privatestatic String gameOpponent;

publicstatic String gameString;

//set local variables equal to parameters

public game(String date, String venue, String time,double price, String opponent)

{

gameDate = date;

gameVenue = venue;

gameTime = time;

gamePrice = price;

gameOpponent = opponent;

}

//prints out info about the particular game

public String toString()

{

gameString ="\n --";

gameString +="\n Date: " + gameDate +" | ";

gameString +="Venue: " + gameVenue +" | ";

gameString +="Time: " + gameTime +" | ";

gameString +="Price: " + gamePrice +" | ";

gameString +="Opponent: " + gameOpponent +"\n";

gameString +=" --";

return gameString;

}

}

I'm sure the formatting/style and stuff is horrible but if I could just get it to work that would be amazing. Thanks in advance.

Message was edited by:

wdewind

[12389 byte] By [wdewinda] at [2007-11-26 23:40:04]
# 1

I don't understand your first problem.

Your second problem:

for (Iterator it=teamSchedLL.iterator(); it.hasNext(); ) {

game game = (game)it.next();

// do the comparation here, if this is the game want to be searched, then break;

}

mimi_tan1985a at 2007-7-11 15:06:20 > top of Java-index,Java Essentials,New To Java...