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 6 of 6

Thread: Help needed for beginner. Im so confused

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help needed for beginner. Im so confused

    I need help on this. Any suggestions?

    --
    Hashing is a way of mapping keys to addresses so that there is essentially on searching involved. The idea is to apply a hash function to the unique key value for each data entry to determine where it should go into an array (i.e. which bucket it belongs to). Unfortunately, any useful hash function will have collisions – more than one key being mapped to the same hash value. We will handle collisions by making each bucket the beginning of an ArrayList. For this assignment we will use a very simplistic hash map – mod 5.

    You will have at least the following classes:
    1. Node – a node will contain an integer for its unique identification number and a String to hold a name. It should be possible to get the name and key value from a node.
    2. DataList – This will have an ArrayList to hold nodes that hash to the same value mod 5. The mod operator in Java is %. 7 % 2 would equal 1.This class should have a find method that returns the name belonging to a key or say the key is not on the list. It will also require an add method and a toString method which will nicely create a String which can be printed out using System.out.println();
    3. Driver – The driver class will have a loop that constantly shows the user a menu. The user has 4 choices:
    a. 1 – Add a new key, name pair (requires creating a Node)
    b. 2 – Find the name belonging to a key (key is input name is output)
    c. 3 – Display all lists
    d. 4 – End

    I suggest you create an array of size 5 to hold 5 ArrayLists of Nodes. Use mod to determine where a Node belongs. For example, if your array is called bins then
    bins[key %5] would be the correct DataList to put the Node in.


  2. #2
    Member
    Join Date
    Nov 2011
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Help needed for beginner. Im so confused

    Hi,
    Is it a question or suggestion?

    Core java
    Last edited by mr.miku; January 11th, 2012 at 07:09 PM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help needed for beginner. Im so confused

    Suggestion: Start designing each of the classes in that you need. Decide what is each to do and what methods will it need to do it.

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help needed for beginner. Im so confused

    Quote Originally Posted by Norm View Post
    Suggestion: Start designing each of the classes in that you need. Decide what is each to do and what methods will it need to do it.
    well so far i have created 2 classes but im really lost.


    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Scanner;


    public class Driver {

    private Scanner in;
    private Node[] nodes;
    private int numberInArray;
    private Node node;

    public Driver()
    {
    numberInArray = 3;
    nodes = new Node[5];
    in = new Scanner(System.in);
    menu();

    }




    public void menu()
    {
    int choice;

    System.out.println("Enter 1 to add data, 2 to find data, 3 to list all data, and 4 to end");
    choice = in.nextInt(); //No Error Checking.
    if(choice==4)
    {
    System.out.println("Thank you for using the system. good bye");
    }
    while (choice != 4)
    {
    if (choice==1)
    {
    System.out.println("Enter the key then the name");
    numberInArray++;
    node= new Node(in.nextInt(), in.next() );
    //nodes[]=node;
    }
    else if (choice==2)
    {
    System.out.println("Enter the key to be found");

    }
    else if (choice==3)
    {
    for (int index=0;index<numberInArray;index++)
    {
    System.out.println(nodes[index]);

    }
    }
    else
    {
    System.out.println("You must enter one of 1, 2, 3, or 4.");
    }
    System.out.println("Enter 1 to add data, 2 to find data, 3 to list all data, and 4 to end");
    choice = in.nextInt();
    }
    }


    public void listing()
    {
    System.out.println("Here are the numbers:");
    for (int index=0;index<numberInArray;index++)
    {
    System.out.println(nodes[index]);
    }


    public static void main(String[] args) {
    new Driver();
    }
    }



    public class Node {

    private int id;
    private String name;



    public Node(int id, String name)
    {
    this.id=id;
    this.name=name;
    }


    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help needed for beginner. Im so confused

    What questions do you have? Does the code compile and execute?
    If you get errors, please copy and paste the full text here.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Help needed for beginner. Im so confused

    Please wrap your posted code in code tags: [code] to preserve its formatting. See:
    BB Code List - Java Programming Forums - The Java Community

Similar Threads

  1. beginner-urgent java help needed
    By joeyyusiyi22 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 28th, 2011, 10:43 AM
  2. Confused..
    By jadowers in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 5th, 2011, 12:56 PM
  3. [SOLVED] confused
    By joon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 12th, 2011, 11:40 AM
  4. I'm confused...
    By acolar in forum Object Oriented Programming
    Replies: 1
    Last Post: April 14th, 2011, 12:14 PM
  5. [SOLVED] Java beginner is confused....
    By truebluecougarman in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 27th, 2011, 08:50 AM