Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 1st, 2006, 01:16 AM
ELHEK ELHEK is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 ELHEK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 14 sec
Reputation Power: 0
Having errors with 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.

Reply With Quote
  #2  
Old October 1st, 2006, 04:56 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 702 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 23 h 33 m
Reputation Power: 4
array is declared privately in ListDictionary so wordbase1 cannot see it.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Having errors with varibles


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT