errors with some varibles


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: errors with some varibles

Hybrid View

  1. #1
    Join Date
    May 2006
    Posts
    6

    errors with some varibles

    hey guys, ive been constantly strugglying to get my code working but have had no luck. i have 2 classes, ListDictionary.java & wordbase1.java which are both linked lists that have an inner node class. ListDictionary.java is an array of linked lists, which reads words in from a text file called dictionary.txt, where for the array every element of the array represents a letter of the alphabet, and contains a linked list of words in alphabetically order starting with that letter. The wordbase1.java is suppose to be a linked list containing all the words in the dictionary which is of 4 letters or less in length, in alphabetically order, and i seem to be getting errors with my array varible. My code is below, any help would be great!

    Code:
    public class wordbase1 extends ListDictionary
    {
       private wordbase head;
       private ListDictionary insert;
    
       public wordbase1(ListDictionary insert)
       {
          super();
          this.insert = insert;
          head = null;
       }
    
       public void insertDictionary()
       {
          insert.addToDictionary();
          wordbase p = new wordbase(array[0].getWord());
          for(int i = 0; i < 26; i++)
          {
             p.getWord() = array[i].getWord();
             if( (array[i].getWord()).length() <= 4)
             {
                if(head == null)
                {
                   head = p;
                }
                else if(head.word.compareTo(p.word) >=0)
                {
                   p.next = head;
                   head = p;
                }
                else
                {
                   wordbase node = head;
                   while((node.next != null) && ((node.next).word).compareTo(p.word) < 0)
                   {
                      node = node.next;
                   }
                   p.next = node.next;
                   node.next = p;
                }
             }
          }
       }
    
       public class wordbase extends NodeDictionary
       {
          private int flag;
          private wordbase next;
    
          public wordbase(String word)
          {
             super(word);
             flag = 0;
             next = null;
          }
    
          public String getWord()
          {
             super.getWord();
          }
       }
    }
    Code:
    import java.util.*;
    import java.io.*;
    public class ListDictionary
    {
       private NodeDictionary head;
       private ListDictionary[] array;
    
       public ListDictionary()
       {
          head = null;
          array = new ListDictionary[26];
       }
    
       public NodeDictionary search(String word)
       {
          NodeDictionary p = head;
          String dataAtPosition;
          while(p != null)
          {
             dataAtPosition = p.word;
             if( dataAtPosition.equals(word))
             {
                return p;
             }
             p = p.next;
          }
          return null;
       }
    
       public boolean retrieveWord(String word)
       {
          return (search(word) != null);
       }
    
    
       public void showList()
       {
          NodeDictionary p = head;
          while(p !=null)
          {
             System.out.println(p.word);
             p = p.next;
          }
       }
    
       public ListDictionary[] getArray()
       {
          return array;
       }
    
       public void setArray(ListDictionary[] array)
       {
          this.array = array;
       }
    
       public void addToDictionary()
       {
          try
          {
             BufferedReader input = new BufferedReader(new FileReader("dictionary"));
             String line = "";
             char arrayLine; //is the words in dictionary.txt gonna be upper  or lower case
             while(line != null)
             {
                line = input.readLine();
                arrayLine = (char)line.charAt(0);
                switch(arrayLine)
                {
                   case 'A':
                   case 'a':
                      array[0].insert(line);
                      break;
                   case 'B':
                   case 'b':
                      array[1].insert(line);
                      break;
                   case 'C':
                   case 'c':
                      array[2].insert(line);
                      break;
                   case 'D':
                   case 'd':
                      array[4].insert(line);
                      break;
                   case 'E':
                   case 'e':
                      array[5].insert(line);
                      break;
                   case 'F':
                   case 'f':
                      array[6].insert(line);
                      break;
                   case 'G':
                   case 'g':
                      array[7].insert(line);
                      break;
                   case 'H':
                   case 'h':
                      array[8].insert(line);
                      break;
                   case 'I':
                   case 'i':
                      array[9].insert(line);
                      break;
                   case 'K':
                   case 'k':
                      array[10].insert(line);
                      break;
                   case 'L':
                   case 'l':
                      array[11].insert(line);
                      break;
                   case 'M':
                   case 'm':
                      array[12].insert(line);
                      break;
                   case 'N':
                   case 'n':
                      array[13].insert(line);
                      break;
                   case 'O':
                   case 'o':
                      array[14].insert(line);
                      break;
                   case 'P':
                   case 'p':
                      array[15].insert(line);
                      break;
                   case 'Q':
                   case 'q':
                      array[16].insert(line);
                      break;
                   case 'R':
                   case 'r':
                      array[17].insert(line);
                      break;
                   case 'S':
                   case 's':
                      array[18].insert(line);
                      break;
                   case 'T':
                   case 't':
                      array[19].insert(line);
                      break;
                   case 'U':
                   case 'u':
                      array[20].insert(line);
                      break;
                   case 'V':
                   case 'v':
                      array[21].insert(line);
                      break;
                   case 'W':
                   case 'w':
                      array[22].insert(line);
                      break;
                   case 'X':
                   case 'x':
                      array[23].insert(line);
                      break;
                   case 'Y':
                   case 'y':
                      array[24].insert(line);
                      break;
                   case 'Z':
                   case 'z':
                      array[25].insert(line);
                      break;
                   default:
                      System.out.println("This word does not start with a alphabetically char");
                      break;
                }
             }
          }
          catch(FileNotFoundException e)
          {
                System.out.println("File opening problem");
          }
          catch(IOException e)
          {
                System.out.println("File reading problem");
          }
       }
    
       public void insert(String word)
       {
          NodeDictionary p = new NodeDictionary(word);
          if(head == null)
          {
             head = p;
          }
          else if( (head.word).compareTo(p.word) >= 0 )
          {
             p.next = head;
             head = p;
          }
          else
          {
             NodeDictionary node = head;
             while( (node.next != null) && ((node.next).word).compareTo(p.word) < 0 )
             {
                node = node.next;
             }
             p.next = node.next;
             node.next = p;
          }
       }
    
       public class NodeDictionary
       {
          protected String word;
          private NodeDictionary next;
    
          public NodeDictionary(String word)
          {
             this.word = word;
             next = null;
          }
    
          public String getWord()
          {
             return word;
          }
       }
    
    }
    the errors im getting are...
    Code:
    wordbase1.java:27: cannot find symbol
    symbol  : method getWord()
    location: class ListDictionary
          wordbase p = new wordbase(array[0].getWord());
                                         ^
    wordbase1.java:30: unexpected type
    required: variable
    found   : value
             p.getWord() = array[i].getWord();
                      ^
    wordbase1.java:30: cannot find symbol
    symbol  : method getWord()
    location: class ListDictionary
             p.getWord() = array[i].getWord();
                                ^
    wordbase1.java:31: cannot find symbol
    symbol  : method getWord()
    location: class ListDictionary
             if( (array[i].getWord()).length() <= 4)
                       ^
    4 errors
    I have been trying to fix it for a while but no luck yet, any help would be great.

  2. #2
    Join Date
    Sep 2006
    Posts
    68
    I)
    >> wordbase p = new wordbase(array[0].getWord());
    ListDictionary.wordbase p = new ListDictionary.wordbase(array[0].getWord());

    II and III)
    You can't do such way
    >> p.getWord() = array[i].getWord();
    use
    p.setWord(array[i].getWord());

    where
    public String setWord(String wrd)
    {
    word = wrd;
    }

    IV)
    change
    >> private ListDictionary[] array;
    to
    public ListDictionary[] array;

Similar Threads

  1. Replies: 1
    Last Post: 05-29-2002, 04:16 PM
  2. Replies: 2
    Last Post: 09-04-2001, 08:59 PM
  3. Error Handler...
    By gurpreet kapoor in forum VB Classic
    Replies: 0
    Last Post: 09-28-2000, 08:01 AM
  4. Turning API Errors into Basic Errors
    By Jim Pragit in forum VB Classic
    Replies: 14
    Last Post: 04-18-2000, 03:48 AM
  5. Turning API Errors into Basic Errors
    By Jim Pragit in forum VB Classic
    Replies: 0
    Last Post: 04-13-2000, 02:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center