Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

    Default Programming with Binary Search Tree

    I need a help in making a program called Car.java where it reads a list of names from a file in a specific format and build binary search tree of names. Then the program be queried by user name for the Car's number, photo.

    picture file attached --> pictures.zip

    The program should take the name from the list.txt file as a command line argument. An example run of
    the program might start like this:
    > java Car list.txt

    Each line of the file represents one name in comma delimited format. Each line contains the name,
    number, and photo filename, in that order separated by commas. (See attached file) The program
    should read in the file line by line, separate out each piece and build a binary search tree of Cars
    sorted by name (alphabetical order).

    The program should loop, asking the user for a command. The following commands
    should be supported:

    • number CAR_NAME
    -- The program should output the car number of the car with CAR_NAME
    •view CAR_NAME
    -- The program should display the photo of the car with name CAR_NAME

    Example Run
    > java CAR_NAME list.txt
    > number Audi
    Number: 500
    > view BMW
    ( a window will be popped showing the picture)


    Addtional program that is needed to write Car.java
    Java Code:
    /**
     * Abstract class to define a binary tree.  
     */
    public abstract class BTNode
    {
     /////////// Fields/////////
      
      private BTNode left; // Left link
      private BTNode right; // Right link
      
     //////Constructors//////
      
      /**
       * Constructor to create a node with an int.
       */
      public BTNode()
      {
        this.left = null;
        this.right = null;
      }
    
      /////Methods//////
      
      /**
       * Accessor Method.
       */
      public BTNode getLeft() 
      { 
        return left; 
      }
    
      /**
       * Modifier Method.
       */
      public void setLeft(BTNode left) 
      { 
        this.left = left; 
      }
      
      /**
       * Accessor Method.
       */
      public BTNode getRight() 
      { 
        return right; 
      }
    
      /**
       * Modifier Method.
       */
      public void setRight(BTNode right) 
      { 
        this.right = right; 
      }
    
    }
    My program

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class Car {
      
      public static void main(String[] args){
        
        Scanner scan = new Scanner(System.in);
        
      BufferedReader reader = null; 
      
    
    }
    }

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    Well, this sure sound like an "here's my assignment, do it for me" type of post. Think about it a bit more, I see your techer supplied you with an abstract representation of the BST, do you know what properties it has? Start with the implementation of the BST, and then go forward from there.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by racewithferrari View Post
    I need a help in making a program called Car.java where it reads a list of names from a file in a specific format and build binary search tree of names. Then the program be queried by user name for the Car's number, photo.

    picture file attached --> pictures.zip

    The program should take the name from the list.txt file as a command line argument. An example run of
    the program might start like this:
    > java Car list.txt

    Each line of the file represents one name in comma delimited format. Each line contains the name,
    number, and photo filename, in that order separated by commas. (See attached file) The program
    should read in the file line by line, separate out each piece and build a binary search tree of Cars
    sorted by name (alphabetical order).

    The program should loop, asking the user for a command. The following commands
    should be supported:

    • number CAR_NAME
    -- The program should output the car number of the car with CAR_NAME
    •view CAR_NAME
    -- The program should display the photo of the car with name CAR_NAME

    Example Run
    > java CAR_NAME list.txt
    > number Audi
    Number: 500
    > view BMW
    ( a window will be popped showing the picture)


    Addtional program that is needed to write Car.java
    Java Code:
    /**
     * Abstract class to define a binary tree.  
     */
    public abstract class BTNode
    {
     /////////// Fields/////////
      
      private BTNode left; // Left link
      private BTNode right; // Right link
      
     //////Constructors//////
      
      /**
       * Constructor to create a node with an int.
       */
      public BTNode()
      {
        this.left = null;
        this.right = null;
      }
    
      /////Methods//////
      
      /**
       * Accessor Method.
       */
      public BTNode getLeft() 
      { 
        return left; 
      }
    
      /**
       * Modifier Method.
       */
      public void setLeft(BTNode left) 
      { 
        this.left = left; 
      }
      
      /**
       * Accessor Method.
       */
      public BTNode getRight() 
      { 
        return right; 
      }
    
      /**
       * Modifier Method.
       */
      public void setRight(BTNode right) 
      { 
        this.right = right; 
      }
    
    }
    My program

    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class Car {
      
      public static void main(String[] args){
        
        Scanner scan = new Scanner(System.in);
        
      BufferedReader reader = null; 
      
    
    }
    }


    Agrees with Moon. What is your current specific question(s)?
    Last edited by Fubarable; 04-17-2010 at 07:26 PM. Reason: post quoted to avoid deletions as per previous thread

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2010, 07:40 AM
  2. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  3. Binary Search Tree
    By anmadie in forum New To Java
    Replies: 5
    Last Post: 11-17-2009, 02:39 AM
  4. Binary Search Tree
    By Goo in forum New To Java
    Replies: 0
    Last Post: 03-06-2009, 04:46 PM
  5. Binary Search Tree
    By michael_mke in forum New To Java
    Replies: 3
    Last Post: 12-04-2008, 02:03 AM

Tags for this Thread

Posting Permissions

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