Compiling error in java, help?

Discussion in 'OT Technology' started by orangespider, Dec 8, 2004.

  1. orangespider

    orangespider This is the title that appears beneath your name o

    Joined:
    Jan 13, 2002
    Messages:
    629
    Likes Received:
    0
    Code:
    import java.util.Scanner;
    
    public class LetterCount
    {
       final int NUMCHARS = 26;
       int number;
    	char name;
       private int[] frequency = new int[NUMCHARS];
       private LetterPair[] pair = new LetterPair[NUMCHARS];
       char current;   // the current character being processed
       int other = 0;  // counter for non-alphabetics
    
    public LetterCount ()
       {
    	   Scanner scan = new Scanner(System.in);
          System.out.println ("Enter a sentence:");
          String line = scan.nextLine();
          line = line.toLowerCase();
    		
          //  Count the number of each letter occurence
          for (int ch = 0; ch < line.length(); ch++)
          {
             current = line.charAt(ch);
             if (current >= 'a' && current <= 'z')
                frequency[current-'a']++;
             else
                other++;
          }
    
          //  transfer()?
    		for (int test = 0; test <= NUMCHARS; test++)
    		{
    		  if (frequency[test] != 0)
    		     {
    			  number = frequency[test];
    			  name = (char)(test + 'a');
    			  transfer(name, number);
    		     }
    		  test++;
    		}
    
          //  Print the results
          System.out.println ();
          for (int letter=0; letter < frequency.length; letter++)
          {
             System.out.print ( (char) (letter + 'a') );
             System.out.println (": " + frequency[letter]);
          }
    
          System.out.println ();
          System.out.println ("Non-alphabetic characters: " + other);
       }
    	
    public static transfer (char name, int number) 
        {
          LetterPair.setLowerCase(name);
    		LetterPair.setNumber(number);
        }
    }
    
    it's at the very end of the code i guess, i keep getting:

    "LetterCount.java:54: invalid method declaration; return type required
    public static transfer (char name, int number) "

    what does it mean? and how can i transfer the name and number i get here to the LetterPair array? :wtc:
     
  2. toraji

    toraji New Member

    Joined:
    Jan 19, 2004
    Messages:
    6,790
    Likes Received:
    0
    Location:
    車の中
    ... u need return types defined in the methods.. void if none..

    and since your arrays are global, you can use them in each method.

    so just copy the letter into each array ..
    or whatever you need to do
     
  3. orangespider

    orangespider This is the title that appears beneath your name o

    Joined:
    Jan 13, 2002
    Messages:
    629
    Likes Received:
    0
    i'm confused, by putting the setLowerCase and setNumber, i'm trying to copy the letter and number into the array. I need to have an array of objects with letter and number for each object. and i'm trying to copy over the numbers i get in the frequency array. :confused: i'm confusing myself now.
     
  4. toraji

    toraji New Member

    Joined:
    Jan 19, 2004
    Messages:
    6,790
    Likes Received:
    0
    Location:
    車の中
    look its not that hard..

    read in a word using string tokenizer.

    compare each letter.. letter for letter.
    once you find the letter.. increment the corresponding place in your array.

    thats about all you need to do.

    the setLowerCase.. changes your whole string to lower case.

    I'm not even sure what setnumber does, but its probably trying to correlate
    a letter to its corresponding number. that shouldnt be too difficult either,
    by just doing a letter to letter comparison. or check its ascii value.
     

Share This Page