Results 1 to 4 of 4
  1. #1
    feastfulsaint is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default Problem with a output

    I created a code with a binary tree and it compiles perfectly. However, when I run it nothing prints out. I had been on this for hours now and I am burnt out. Thank you in advance.

    Code #1
    Java Code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.util.ArrayList;
    
    public class FitopiaVer2
    {
      ArrayList<MembershipNode> members;
      protected MembershipNode root;
      public FitopiaVer2()
      {
        members = new ArrayList<MembershipNode>();
        root = null;
      }
      public void insert(int element, String n)
      {
        MembershipNode mem = root, prev = null;
        while(mem != null)
        {
          prev = mem;
          if(mem.key < element)
            mem = mem.right;
          else mem = mem.left;
        }
        if (mem == null)
          mem = new MembershipNode(element, n);
        else if(prev.key < element)
          prev.right = new MembershipNode( element, n);
        else prev.left = new MembershipNode(element, n);
      }
      public void join(MembershipNode member)
      {
        members.add(member);
      }
      public int numberOfMembers()
      {
        return members.size();
      }
    }
    Code # 2
    Java Code:
    public class MembershipNode
    {
      protected int key;
      protected String name;
      protected int month;
      protected int membershipNumber;
      protected MembershipNode left, right;
      
      public MembershipNode()
      {
        left = right = null;
      }
      
      public MembershipNode(int ele, String name)
      {
        this(ele, name, null, null);
      }
      
      public MembershipNode(int ele, String Name, MembershipNode l, MembershipNode r)
      {
        key = ele;
        this.name = Name;
        left = l;
        right = r;
      }
     
      public void open()
      {
        System.out.print(key + " ");
      }
      
      public String toString()
      {
        return " " + key + " " + name;
      }
      MembershipNode(String name, int month, int membershipNumber)
      {
         if(month >= 1 && month <= 12)
      {
        this.name = name;
        this.month = month;
        this.membershipNumber = membershipNumber;
      }
      else
      {
        System.out.println ("Invalid month (1, 12):" + month);
      }
    }
    }
    Code # 3
    Java Code:
    public class FitopiaVer2Demo
    {
      private static FitopiaVer2 club;
      
      public static void main(String[] args)
      {
       club = new FitopiaVer2();
      }
      
      public void demo()
      {
        club.join(new MembershipNode("Victor", 1, 7));
        club.join(new MembershipNode("Sydney", 5, 2));
        club.join(new MembershipNode("Bobby", 2, 4));
        club.join(new MembershipNode("Candy", 4, 6));
        club.join(new MembershipNode("David", 11, 8));
        System.out.println("Fitopia has " + club.numberOfMembers() + "members.");
      }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    However, when I run it nothing prints out.

    Yes, nothing prints out.

    Java Code:
    public static void main(String[] args)
      {
       club = new FitopiaVer2();
      }

    You create a club and then ... nothing. The program just ends at that point.

  3. #3
    feastfulsaint is offline Member
    Join Date
    Jul 2010
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    Yes, nothing prints out.

    Java Code:
    public static void main(String[] args)
      {
       club = new FitopiaVer2();
      }

    You create a club and then ... nothing. The program just ends at that point.
    Oh man, I was just too zoned out. I can't believe I made that much of an obvious mistake. Sorry I was just too tired, I'll fix it in the morning. Hopefully it will run and print. Thank you.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Yeah, sleeping on a problem is often productive. Good luck!

Similar Threads

  1. problem with output of code
    By amosexy in forum New To Java
    Replies: 15
    Last Post: 07-05-2010, 07:57 PM
  2. xml output problem
    By tsili in forum XML
    Replies: 2
    Last Post: 05-24-2010, 01:27 AM
  3. problem with output of jar file
    By nishant.4545 in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2009, 05:00 PM
  4. Output Problem
    By jazz2k8 in forum New To Java
    Replies: 4
    Last Post: 05-26-2008, 11:59 AM
  5. Output problem
    By jvasilj1 in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 07:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •