binary search tree to store club members and display membership ID and names
I have been tasked to create a ClubMember class that represents a member of a fitness club and a tree class to use in the ClubMember class along with a menu that prompts the user to 1) Enter a new member. 2) Display the membership list. 3) Exit the program. I must use a binary search tree to store a set of club members based on their membership ID number and display the membership ID along with the name of the club member. This is what I have so far:
Code Java:
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ClubMember { //creates clubMember class/
public static void main(String[] args)
{
DataOutputStream ostream;
final int DONE = 999;
int id;
String lastName;
String firstName;
try
{
ostream = new DataOutputStream
(new FileOutputStream("MemID.dat"));
System.out.print("Enter ID number or " + DONE + " to quit >> ");
//id = input.nextInt();
while(id != DONE)
{
//input.nextLine();
System.out.print("Enter last name >> ");
//lastName = input.nextLine();
System.out.print("Enter first name >> ");
firstName = input.nextLine();
ostream.writeInt(id);
ostream.writeUTF(lastName);
ostream.writeUTF(firstName);
System.out.print("Enter ID number or " + DONE + " to quit >> ");
id = input.nextInt();
}
ostream.close();
}
catch(IOException e)
{
System.err.println("Error opening file");
}
catch(InputMismatchException e)
{
System.err.println("Invalid data entry");
}
}
}
I'm not sure where to place the menu or the binary search tree, could anyone give me a hand? Thanks
Re: binary search tree to store club members and display membership ID and names
The BST should be in its own class.
The menu could be in a method that is used to get user input.
BTW The code is not properly formatted. Nested statements should be indented 3-4 spaces.
Re: binary search tree to store club members and display membership ID and names
Thanks, I usualy format after I get the code to compile and run (I know it's a bad habit) it helps me see things line by line.
Re: binary search tree to store club members and display membership ID and names
Quote:
it helps me see things line by line.
That's strange. Most of us need the indentation to see the logic of a program. Without that it is very hard to understand the program's structure. Personally I won't try to work with unformatted code. It's just too hard to understand.