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: help me

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

    Default help me

    hi...........
    I have to make a java program and I faced a problem to do it. please go to the txt file which I have been attached and see if you can do this program with java language.

    I have to do it in 3 days.

    if you done it please send it to my e-mail: SM-DH7@htmail.com

    thank you.......
    Attached Files Attached Files
    Last edited by oman117; December 22nd, 2009 at 01:10 PM. Reason: attachment

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help me

    Sorry, we will not do your homework for you. We will help you, though. Tell us what specifically you need help with and what you have tried (aka. code).

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

    Default Re: help me

    hello.....
    ok just make the struture to me using dr.java
    SM-DH7@hotmail.com

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help me

    This isn't a beginners assignment so i'll assume that you know the basics of Java already?

    If you want people here to help you with home work, you will need to show you have made an effort.

    Here is the start. At least try to add your own code and then we can help you move forward.

    public class Dr {
     
     
    	public static void main(String[] args) {
     
     
    	}
     
    }

    Take a look here:

    Java Code Snippets and Tutorials - Java Programming Forums

    You will find examples on how to use the Scanner class which will make your life easier.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

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

    Default Re: help me

    okay I tried to do the task. see my try, I attached it. please make corriction on the code and try to send it to me on my e-mail. because i have to submit it on satarday 9:00 am

    thanx

    edit: code posted below

    import java.util.Scanner;
    public class faisal222{
      public static void main(String[]args){
       Scanner sca=new Scanner(System.in);
       SLL letterList= new SLL();
       DLL wordList=new DLL();   
        int selectout=0;
        int selectin=0;
        String input;
        Scanner sc=new Scanner(System.in);
       while(selectout!=6){
          System.out.println("1-Print dictionary \n2-Search for word\n3-Insert word\n4-Delete word"+
                             "\n5-print report of the words"+
                             "\n6-exit");
        System.out.print("\nYour select:");
        selectout=sca.nextInt();
        switch(selectout){
          case 1:
              System.out.println("Enter letter you want to print its words:");
              char ins=sc.next().charAt(0);
              SLLNode current=new SLLNode(ins,null);
              letterList.insert(ins,null);
              System.out.println("1-Print Forward List\n2-Print Backward List");
              System.out.print("Choice:");
              selectin=sc.nextInt();
              if(selectin==1){
              wordList.printForward();}
                else wordList.printBackward(); 
              break;
     
          case 2:
            System.out.println("Enter word that you search for:");
            String search=sc.next();
            wordList.searchWord(search);
            System.out.println();
            break;
          case 3:
             System.out.println("1-Enter letter that word start with it:");
             System.out.println("Letter:");
             char insletter=sc.next().charAt(0); 
             SLLNode current2=new SLLNode(insletter,null);
             letterList.insert(insletter,null);
              System.out.println("Word:");
              input=sc.next();
              DLLNode<String> insword=new DLLNode<String>(input);//create the node to be inserted
              wordList.insertWord(insword,null);
     
              break;
     
          case 4:
                System.out.println("Word to be deleted:");
                input=sc.next();
                DLLNode del=wordList.findWord(input);//node to delete
                if(del==null)
                  System.out.println("Error:Word doesn't exist!");
                else
                wordList.deleteWord(del);
     
                break;
          case 5:
            System.out.println("Total number of words:"+wordList.getSize());
            letterList.printList();
            break;
          case 6:
             System.exit(0);
              break;
            default: System.out.println("invalid input, try again");
        } 
     
       }  
      }
    }
    /*******************************************************************/
     
     class SLL{
      SLLNode first;
      public SLL(){
        first= null;
      }
     
    public void printList(){
        if(first==null) //letterList is empty
          System.out.println("dictionary is empty!");
        else{//print letts one by one
          SLLNode current=first;
          while(current!=null){
            System.out.println(current.lett+":");
            current=current.next;
          }
     
          System.out.println();
        }
      }
     
    public void insert(char lett,SLLNode previous){
        SLLNode ins = new SLLNode(lett,null);
        if(previous==null){
          ins.next=first;
          first=ins;}
        else{
          ins.next=previous.next;
          previous.next=ins;
        }
      }
     
     }
     
    /*******************************************************************/
    class DLL{
      DLLNode first;
      DLLNode last;
    public DLL(){
        first=last=null;
      } 
     
    public void printForward(){
        if(first==null){
          System.out.println("The wordList is empty");
        }
        else{
          DLLNode current=first;
          while(current!=null){
            System.out.print(current.word+" ");
            current=current.next;
          }
          System.out.println("\n");
        }
      }
    public void printBackward(){
         if(first==null){
          System.out.println("The wordList is empty");
        }
        else{
          DLLNode current=last;
          while(current!=null){
            System.out.print(current.word+" ");
            current=current.previous;
          }
          System.out.println("\n");
        }
      }
    public DLLNode searchWord(String word){
      DLLNode current=first;
      if(current!=null && (current.word.equals(word))){
        current=current.next;
        System.out.println("Search success: Word does exist in dictionary");
    } 
      else
      System.out.println("Search success: Word doesn't exist in dictionary");
    return current;
    }
    public DLLNode findWord(String word){
          DLLNode current=first;
          while(current!=null && !(current.word.equals(word))){
          current=current.next;
          }
           return current;  
     }
     
    public void insertWord(DLLNode insword,DLLNode pred){
        if(pred==null){ //user wants to insert at the beginning
          //two cases: 1-empty wordList, 2-not empty
          if(first==null)
            first=last=insword;
          else{
            insword.next=first;
            first.previous=insword;
            first=insword;
          }
      }
      }
      public void deleteWord(DLLNode del){
        if(del==first){//node to delet is the first one
          first=first.next;
          //two cases:1-wordList 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;
       }
    }
     
    /**************************************************************/
     class SLLNode{
      char lett; 
      SLLNode next;
      SLLNode privous;
      //SLLNode firstWord;
      //SLLNode lastWord;
      public SLLNode(char lett,SLLNode next){
        this.lett=lett;
        this.next=next;
        //this.SLLNode lastWord=DLLNode previous
        //this.SLLNode firstWord=DLLNode next
      }
       }
     
     
    class DLLNode<T>{
      T word;
      DLLNode next; // you can call succ or successor
      DLLNode previous; //you can also call pred or predessor
     
      public DLLNode(T word){
        next=previous=null;
        this.word=word;
      }
     
    }
    Attached Files Attached Files
    Last edited by helloworld922; December 25th, 2009 at 11:33 AM.

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

    Default Re: help me

    The way it usually works on these forums is that you post the code, explain what it is supposed to do, and what is happening instead, post the full text of any errors you get, and explain the things you have tried to fix it. Then we tell you what we think the problem might be, and you go away and try to fix it.

    Code forums help those who help themselves.

    Seasonal Greetings!

  7. #7
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: help me

    It's ok to attach longer pieces of code as an attachment. The problem you have is that you declared DLLNode to take a generic arguments:

    DLLNode<T>
    {
      // DLLNode code definition
    }

    So, everytime you declare or instantiate a DLLNode variable, you must tell it what generic type you want it to use:

    DLLNode<Double> myDLLNode = new DLLNode<Double>(5.0)

    However, words generally are strings, so I suspect you probably can remove the generic declaration all-together, or if you're not allowed to, simply declare all your DLLNode's as having the generic type of String.

    DLLNode<String> word1 = new DLLNode<String>("Hello");

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

    Default Re: help me

    Something tells me that's not all the OP's own code - why would he declare a class using generics then forget how to use them to instantiate it?