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: Help with Dynamic linked list (Binary Trees)

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Location
    UK
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Dynamic linked list (Binary Trees)

    Hi & thanks in advance for any help offered.

    I'm trying to implement an Office class that contains an inner class: WorkerNode. The WorkerNode class has a name attribute (String) and WorkerNode attributes for boss, peer and subordinate. The attributes of Office are manager and current which are WorkerNode references. The manager refers to the entry point of the structure and current is the current node in the structure. For simplicity, i'm going to try to limit it to 3 levels and assume that the names are unique.
    I've put together a Office class that containing main and provided the code I've worked on so far.
    Ideally, the result would display the following:

    The name, boss’s name and subordinate names for the current object e.g if the current object is Amy then should display
    Amy reports to Barry
    Harry
    Fiona



    I'm really struggling with dynamic linked lists and any help offered would be greatly appreciated.
    Thanks

    Pip

    Office class:

    public class Office {
    	public static void main(String[] args) {
    		String name=Input.getString("input the manager's name: ");
    		Office office=new Office(name);
    		int option;
    		boolean found;
    		do{
    			System.out.println("0: quit");
    			System.out.println("1: add subordinate to current");
    			System.out.println("2: find worker");
    			System.out.println("3: display current");
    			System.out.println("4: display office");
    			option=Input.getInteger("input option: ");
    			switch(option){
    				case 1:	name=Input.getString("input the subordinate's name: ");
    						office.addSubordinate(name);
    						break;
    				case 2:	name=Input.getString("input the worker's name: ");
    						found=office.findWorker(name);
    						if(!found)
    							System.out.println("not found");
    						break;
    				case 3:	office.displayCurrent();
    						break;
    				case 4:	office.displayOffice();
    						break;
    			}
    		}while(option!=0);
    	}
     
    }

    Input Class:

    import java.io.*;
    public class Input{
    	private static BufferedReader input=new BufferedReader
                    		(new InputStreamReader(System.in));
        public static Character getCharacter(String prompt){
            Character value;
            System.out.print(prompt);
            try{
                value=Input.input.readLine().charAt(0);
            }
            catch(Exception error){
    		  	// error condition
                value=null;
            }
            return value;
        }
        public static Double getDouble(String prompt){
            Double value;
            System.out.print(prompt);
            try{
                value=Double.parseDouble(Input.input.readLine());
            }
            catch(Exception error){
    		  	// error condition
                value=null;
            }
            return value;
        }
        public static Integer getInteger(String prompt){
            Integer value;
            System.out.print(prompt);
            try{
                value=Integer.parseInt(Input.input.readLine());
            }
            catch(Exception error){
    		  	// error condition
                value=null;
            }
            return value;
        }
        public static String getString(String prompt){
            String string;
            System.out.print(prompt);
            try{
                string=Input.input.readLine();
            }
            catch(Exception error){
    		  	// error condition
                string=null;
            }
            return string;
        }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help with Dynamic linked list (Binary Trees)

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers, including a few "house rules" that will make you a more confident user of this forum.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Location
    UK
    Posts
    6
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with Dynamic linked list (Binary Trees)

    Apologies - will post any future code properly
    Thanks for the 'heads-up'

    Pip

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help with Dynamic linked list (Binary Trees)

    You can edit your post so that the code there is posted correctly.

Similar Threads

  1. binary trees
    By game06 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2013, 07:58 AM
  2. [Linked List] Problems deleting items from a linked list
    By KLVTZ in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 8th, 2013, 09:21 PM
  3. [Linked List] Problems deleting items from a linked list
    By KLVTZ in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 8th, 2013, 07:52 PM
  4. Replies: 1
    Last Post: October 25th, 2012, 02:03 PM
  5. Linked list Schminked list help with Nodes Please
    By Bially in forum Collections and Generics
    Replies: 1
    Last Post: September 29th, 2011, 03:20 PM

Tags for this Thread