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.
http://www4.0zz0.com/2009/12/16/08/831399342.jpg
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 can’t, 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 can’t 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 doesn’t 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; it’s because adding and deleting from DLLs is more convenient.
Re: need help in my assignment guys :(
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...
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 >>>
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");
}
}
}
}
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");
}
}
}
}
Re: need help in my assignment guys :(
If you want your code to be readable, post it formatted and in [CODE]...[/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.
Re: need help in my assignment guys :(