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

Thread: need help in my assignment guys :(

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy need help in my assignment guys :(

    I have got this assignment and I'm really new to this world (Java world)>

    I really wanna your help guys

    Description:
    In this assignment you are going to design and implement a Dictionary system that enables the user to efficiently add, remove, and search for words using a menu-driven system. The words will be organized as shown in figure 1 below. As you can see the system is a singly linked list of doubly linked lists. Read the technical details explained later to further understand how the system should behave. The completion of this assignment is heavily dependent on singly and doubly linked lists.




    Technical Details:
    The system consists of three main entities: dictionary, letter, and word. Clearly, we need to create only one dictionary that consists of many letters, which in turn consist of many words. Initially we should have an empty dictionary, which means no letters and no words. The letters will be stored in a singly linked list and words in doubly linked lists. The justification for this design will be explained later.
    The dictionary entity has a field pointing at the first letter in the list. Each letter entity has three pointers: one pointing at the next letter, the second pointing at the first word and another pointing at the last word in the list. Each word entity has two pointers: one pointing at the previous, and another pointing at the next word in the list.
    Since there are 26 letters in the English alphabet, the maximum number of elements in the singly linked list is 26. To make things easier, we will assume that we are only dealing with lowercase letters (a  z).
    The letters in the singly linked list and the words in the doubly linked lists should be stored in an alphabetical order. So you cant, for example, have the letter e before a.
    The letter entity should have an additional field that keeps track of how many words start with this letter. So for example the letter m in figure 1, should have this field = 4 because there are four words in this list.
    A letter should appear in the list only if there are words starting with it. For example, you cant find the letter a in figure 1 because there are no words starting with this letter.
    Once a letter is added to the list, it will never be removed even if we remove the words linked to it.



    Requirements:
    You must create a menu that enables the user to perform the following tasks in a similar manner to what we did in the lab. The tasks are:
    1. Search for a specific word.
    In this task the user will provide a word that you need to report whether it exists in the dictionary or not. Your search method should be efficient.
    2. Add a new word.
    In this task, the user will provide a new word to add it to the dictionary. You must add the new word in the correct DLL (under the correct letter) and in the correct alphabetical order. If the letter doesnt already exist, you should add it. You should also increase the number of words which is a field stored in the letter entity.


    3. Delete an existing word.
    In this task, the user will provide a word to delete. Of course you will need to search for this word first and make sure it exists before you can delete it. You can use the search method of task 1 to complete this task. You need to decrease the number of words by one if the deletion is successful.
    4. Report the number of words that start with a specific letter and print those words to the screen. You should give two options here: forward or backward print.
    5. Print all the words that currently exist in the dictionary. Also print their total number.
    The output for figure 1, for example, should look like this:

    Total number of words: 10
    c: cat, coin, cold
    e: eye
    m: man, mild, mom, myth
    r: rain, rest

    6. Exit

    I suggest that you create four classes only: Dictionary, Letter, Word, and MainClass. You should be able to see now why I made the words in double linked lists; its because adding and deleting from DLLs is more convenient.


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help in my assignment guys :(

    pleas guys

    any one

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: need help in my assignment guys :(

    Show what you have so far, and explain where you are stuck. I don't think anyone will do your assignment for you...

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help in my assignment guys :(

    we lernt how to deal with only one singly list at a time
    or one doubly list at a time
    but this assignment we are asked to create a singly Linked list of letters and each letter is a doubly linked list of words
    I really straggle with this I cannot do this
    I started to create the classes as we asked in the assignment and they right as my instructor said
    but I couldn't go farther in my assignment
    so, I hope to get 2 or 3 out of 10 because the due date is 26 of this month and that is after 2 days >>>

  5. #5
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help in my assignment guys :(

    this what we implemented in laps


    ///////////////////////////////////////////
    ////////The First Class///////////
    ///////////////////////////////////////////

    public class DLLNode<T>{
    T element;
    DLLNode next; // you can call succ or successor
    DLLNode previous; //you can also call pred or predessor

    public DLLNode(T element){
    next=previous=null;
    this.element=element;
    }

    }
    /////////////////////////////////////////////////






    ///////////////////////////////////////////
    ////////The Second Class///////////
    ///////////////////////////////////////////
    public class DLL{
    DLLNode first;
    DLLNode last;

    public DLL(){
    first=last=null;
    }

    public void printForward(){
    if(first==null){
    System.out.println("The list is empty");
    }
    else{
    DLLNode current=first;
    while(current!=null){
    System.out.print(current.element+" ");
    current=current.next;
    }
    System.out.println("\n");
    }
    }

    public void printBackward(){
    if(first==null){
    System.out.println("The list is empty");
    }
    else{
    DLLNode current=last;
    while(current!=null){
    System.out.print(current.element+" ");
    current=current.previous;
    }
    System.out.println("\n");
    }
    }

    public DLLNode findNode(String element){

    DLLNode current=first;
    while(current!=null && !(current.element.equals(element))){
    current=current.next;
    }

    return current;

    }

    public void insertNode(DLLNode ins,DLLNode pred){
    if(pred==null){ //user wants to insert at the beginning
    //two cases: 1-empty list, 2-not empty
    if(first==null)
    first=last=ins;
    else{
    ins.next=first;
    first.previous=ins;
    first=ins;
    }
    }
    else{//insert after a specific node
    //two cases: 1-after the last node, 2-in the middle
    if(pred==last){
    last.next=ins;
    ins.previous=last;
    last=ins;
    }
    else{
    DLLNode succ=pred.next; //pointer to the successor node
    pred.next=ins;
    ins.next=succ;
    succ.previous=ins;
    ins.previous=pred;
    }
    }

    }

    public void deleteNode(DLLNode del){
    if(del==first){//node to delet is the first one
    first=first.next;
    //two cases:1-list becomes empty, 2-still there are nodes
    if(first==null)
    last=null;
    else
    first.previous=null;
    }
    else if(del==last){//node to delete is the last one
    last=del.previous;
    last.next=null;
    }
    else{//delete a node in the middle
    DLLNode pred=del.previous;
    DLLNode succ=del.next;
    pred.next=succ;
    succ.previous=pred;
    }

    }

    public int getSize(){
    DLLNode current= first;
    int size=0;
    while(current!=null){
    size++;
    current=current.next;
    }
    return size;
    }

    }

    //////////////////////////////////////////////////






    ///////////////////////////////////////////
    ////////The third Class///////////
    ///////////////////////////////////////////

    import java.util.Scanner;
    public class TestDLL{
    public static void main(String []args){

    DLL list=new DLL();

    int userChoice=0;
    int innerChoice=0;
    String input;
    Scanner sc=new Scanner(System.in);
    while(userChoice!=7){
    System.out.println("1-Print Forward List\n2-Print Backward List\n3-Insert a new node"+
    "\n4-Delete an existing node \n5-get size of list\n"+
    "6-exit");
    System.out.print("\nYour Choice:");
    userChoice=sc.nextInt();
    switch(userChoice){
    case 1:
    list.printForward();
    break;

    case 2:
    list.printBackward();
    break;


    case 3:
    System.out.println("1-Insert at the beginning\n2-Somewhere else");
    System.out.print("Choice:");
    innerChoice=sc.nextInt();
    System.out.println("Element:");
    input=sc.next();
    DLLNode<String> ins=new DLLNode<String>(input);//create the node to be inserted
    if(innerChoice==1){//insert at the beginning
    list.insertNode(ins,null);
    }
    else if(innerChoice==2){
    System.out.println("Element after which you want to insert new node:");
    input=sc.next();
    DLLNode pred=list.findNode(input);
    list.insertNode(ins,pred);
    }
    else{
    System.out.println("Invalid input");
    }

    break;

    case 4:
    System.out.println("Element to be deleted:");
    input=sc.next();
    DLLNode del=list.findNode(input);//node to delete
    if(del==null)
    System.out.println("Error:Node doesn't exist!");
    else
    list.deleteNode(del);

    break;
    case 5:
    System.out.println("List size="+list.getSize());
    break;

    case 6:
    System.exit(0);
    break;

    default: System.out.println("invalid input, try again");
    }


    }
    }

    }

  6. #6
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy this what I reach in my assignment so far

    ///////////////////////////////////////////
    ////////The First Class///////////
    ///////////////////////////////////////////

    public class Dictionary{
    Letter firstLetter;

    public Dictionary(){
    firstLetter= null;
    }




    }


    //////////////////////////////////////////


    ///////////////////////////////////////////
    ////////The Second Class///////////
    ///////////////////////////////////////////

    public class Letter{
    char ch;
    Letter nextCh;
    Word firstWord;
    Word lastWord;

    public Letter(){
    firstWord=lastWord=null;
    }

    public Letter(char ch,Letter nextCh){
    this.ch=ch;
    this.nextCh=nextCh;

    }



    public Word findWord(String word){
    Word current=firstWord;
    while(current!=null && !(current.wo.equals(word))){
    current=current.nextWord;
    }

    return current;

    }


    public Word addFirstWord(String word){
    Word firstWord=lastWord=word;
    }

    }

    ///////////////////////////////////




    ///////////////////////////////////////////
    ////////The third Class///////////
    ///////////////////////////////////////////


    public class Word{
    String wo;
    Word nextWord;
    Word previousWord;

    public Word(String wo){
    nextWord=previousWord=null;
    this.wo=wo;
    }

    }


    ////////////////////////////////////////





    //////////////////////////////////////////
    ////////The main Class///////////
    ///////////////////////////////////////////

    import java.util.Scanner;
    public class MainClass{
    public static void main(String []args){

    Dictionary dic=new Dictionary();

    int userChoice=0;
    int innerChoice=0;
    String input;
    Scanner sc=new Scanner(System.in);
    while(userChoice!=7){
    System.out.println("1-Finde a word \n2-Add new word \n3-Delete a word"+
    "\n4-Print List of words in a specific Letter \n5-Print All the words in the dictionary \n"+
    "6-Exit");
    System.out.print("\nYour Choice:");
    userChoice=sc.nextInt();
    switch(userChoice){


    case 1:
    System.out.println("Enter the word you want to find: ");
    String word=sc.next();
    Letter w=dic.search(word);
    if(w==null){
    System.out.println("Word is not Exist");
    }else{
    System.out.println("Word: "+word+" is in the Dictionary");

    }

    break;



    case 2:
    System.out.println("Enter the word you want to Add: ");
    String word=sc.next();
    dic.addNew(word);
    break;


    case 3:


    break;

    case 4:


    break;
    case 5:

    break;

    case 6:
    System.exit(0);
    break;

    default: System.out.println("invalid input, try again");
    }


    }
    }

    }

  7. #7
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: need help in my assignment guys :(

    If you want your code to be readable, post it formatted and in &#91;CODE]...&#91;/CODE] tags.

    You still haven't said exactly which bit of the linked list assignment you are stuck on, or why. Just posting lots of unreadable code doesn't help.

  8. #8
    Junior Member
    Join Date
    Dec 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: need help in my assignment guys :(

    never mind
    thanx overall

Similar Threads

  1. Replies: 5
    Last Post: December 13th, 2009, 06:10 PM
  2. Hi guys
    By fembiz in forum Member Introductions
    Replies: 3
    Last Post: December 11th, 2009, 02:36 AM
  3. need help guys
    By Imeri0n in forum Java Theory & Questions
    Replies: 9
    Last Post: December 3rd, 2009, 08:39 AM
  4. [SOLVED] Some important questions about java programming
    By chronoz13 in forum Java Theory & Questions
    Replies: 12
    Last Post: April 16th, 2009, 02:55 PM