Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: binary search tree to store club members and display membership ID and names

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:
     
     
    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: binary search tree to store club members and display membership ID and names

    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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Binary Search Tree inorder tree traversal
    By Maukkv in forum What's Wrong With My Code?
    Replies: 17
    Last Post: January 26th, 2013, 05:28 PM
  2. Binary Tree Search[HELP]
    By husain2213 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 13th, 2012, 11:33 PM
  3. Binary Search Tree
    By lex25288 in forum Algorithms & Recursion
    Replies: 3
    Last Post: January 19th, 2011, 09:10 AM
  4. Data Structures(Binary Search Tree to AVL Tree)ASAP
    By jfAdik in forum Algorithms & Recursion
    Replies: 2
    Last Post: April 5th, 2010, 03:58 AM
  5. Binary Search Tree
    By Koren3 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 12th, 2009, 09:27 AM