Переменные параметров передачи ошибок

У меня возникли проблемы с конструированием передачи параметров. Я попытался установить переменные String pluralizedWord = makePlural (word) и т. Д. но это не помогло. Я получаю не могу найти ошибку символа для переменных множественного числа и wordWithSuffix. Не могли бы вы взглянуть? Очень ценится. Если я уже не упоминал об этом, это Java. К началу моего кода вы можете увидеть прокомментированные переменные. У меня были эти переменные, опубликованные в глобальном масштабе изначально, но чтобы улучшить мой код, мне нужно иметь только локальные переменные и возвращать переменные, которые необходимо передать через передачу параметров.

 import java.lang.*;
 import java.io.*;
 import java.util.StringTokenizer;
 import java.util.NoSuchElementException;



 public class newVowel {

      public static FileInputStream fileInStream;   //call the FileInputStream and name as fileInStream
      public static InputStreamReader fileInReader; //call the InputStreamReader and name as fileInReader
      public static BufferedReader reader;          //call the BufferedReader and simply name it as such, reader

      //private static String line, word, suffix, plural, wordWithSuffix;   //call String variables
      //private static int length, lengthOfWord, spaceIndex, counter;       //call integer variables to be used later
      //private static char firstLetter, secondLetter, lastLetter, c;       //call the character variables

      public static void initiateFile() throws IOException //the initiateFile method reads the external text file and sets all contents of file into the variable reader
      {
           fileInStream = new FileInputStream("C:\\!!VHSAPCSData\\vowels.txt"); //location of file
           fileInReader = new InputStreamReader(fileInStream);                      //inputs data
           reader = new BufferedReader(fileInReader);                               //reads data
      }

      public static String makePlural(String word)                  //the makePlural method, simply makes the words plural
      {
           String plural;
           int length, lengthOfWord;
           char lastLetter, secondLetter;

           lengthOfWord = word.length();                    //calculates the length of the word
           lastLetter = word.charAt(lengthOfWord-1);        //calculates the last letter
           secondLetter = word.charAt(lengthOfWord-2);      //calculates the second to last letter
           if(((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L')) && ((secondLetter != 'A')||(secondLetter != 'C')||(secondLetter != 'S')||(secondLetter != 'L')))
           {                                                 //this if statement checks for the specified "vowels" A, C, S, and L in specific combinations. If the word ends in only one vowel,
                  plural = word.substring(0, (lengthOfWord-1));//the original word drops the last letter (vowel) as the directions state, and then
                  plural += "G";                                 //"G" is added to the end of the word
           }
           if(((lastLetter != 'A')||(lastLetter != 'C')||(lastLetter != 'S')||(lastLetter != 'L')) && ((secondLetter == 'A')||(secondLetter == 'C')||(secondLetter == 'S')||(secondLetter == 'L')))
                 plural = word + "GH";                      //this if statement checks for the specified "vowels" A, C, S, and L in specific combinations. If, of the last two letters, the second to last letter
                                                        //is a vowel, "GH" is added to the end of the word
           if(((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L')) && ((secondLetter == 'A')||(secondLetter == 'C')||(secondLetter == 'S')||(secondLetter == 'L')))
           {
              String lastChar = Character.toString(lastLetter); //this if statement checks for the specified "vowels" A, C, S, and L in specific combinations. If the word ends in two vowels,
              plural = word + lastChar + "H";                       //then the last letter is doubled and "H" is added to end of word
           }
           String pluralizedWord = plural;
           return pluralizedWord;
     }

     public static String addOnSuffix(String word, String suffix) //this is the addOnSuffix method, hence where the suffix is added onto the word
     {
           String wordWithSuffix;
           int length, lengthOfWord, counter;
           char firstLetter, secondLetter, lastLetter, c;

           lengthOfWord = word.length();                    //calculates length of word
           lastLetter = word.charAt(lengthOfWord-1);        //calculates last letter of word
           secondLetter = word.charAt(lengthOfWord-2);      //calculates second to last letter of word
           firstLetter = suffix.charAt(0);                  //calculates first letter of word
           if(((firstLetter == 'A')||(firstLetter == 'C')||(firstLetter == 'S')||(firstLetter == 'L'))) //if statement which applies if the first letter of word is a "vowel"
           {
               if(((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L')) && ((secondLetter != 'A')&&(secondLetter != 'C')&&(secondLetter != 'S')&&(secondLetter != 'L')))
               {                                            //if statement which applies if the last letter of word is a vowel, yet second to last letter is a "non-vowel"
                   String append = suffix.substring(1); //suffix is appended by dropping first letter of suffix then adding the suffix
                   wordWithSuffix = word + append;
               }
               if(((lastLetter != 'A')&&(lastLetter != 'C')&&(lastLetter != 'S')&&(lastLetter != 'L')) && ((secondLetter == 'A')||(secondLetter == 'C')||(secondLetter == 'S')||(secondLetter == 'L')))
                   wordWithSuffix = word + suffix;                                  //if statement which applies if the second to last letter of word is a vowel, yet last letter is a "non-vowel"
                                                                                //suffix is appended by merely adding it, no change to suffix
                   if(((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L')) && ((secondLetter == 'A')&&(secondLetter == 'C')&&(secondLetter == 'S')&&(secondLetter == 'L')))
                   {                                                                    //if statement which applies if both the second to last and last letters are "vowels," if so
                       String firstChar = Character.toString(firstLetter);              //then the first letter will be added to word, and then the suffix (unchanged)
                       wordWithSuffix = word + firstChar + suffix;          
                   }
           }
           else //complicated else statement that puts together plurals and suffixes of words that don't begin with a "vowel"
           {
               if(((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L')) && ((secondLetter != ('A'))&&(secondLetter != 'C')&&(secondLetter != 'S')&&(secondLetter != 'L')))
               {                                                                    //if the word does not begin with a "vowel" and the last letter does, yet the second to last does not, then
                  String firstChar = Character.toString(firstLetter);           //the first character is parsed to a string firstChar,
                  wordWithSuffix = word + firstChar + suffix;                       //and the word is put together as the word + the first character + add the suffix
               }
               if(((lastLetter != ('A'))&&(lastLetter != 'C')&&(lastLetter != 'S')&&(lastLetter != 'L')) && ((secondLetter == 'A')||(secondLetter == 'C')||(secondLetter == 'S')||(secondLetter == 'L')))
                   wordWithSuffix = word + suffix;                                  //if the word does not begin with a "vowel" and the second to last letter does, yet the last does not, then
               else                                                             //easily enough, the word is put together as the word plus the suffix
               {
                   if((lastLetter == 'A')||(lastLetter == 'C')||(lastLetter == 'S')||(lastLetter == 'L'))
                   {                                                                //if the word does not begin with a "vowel", yet the last letter is a "vowel,"
                       counter = (lengthOfWord-1);                              //assign integer counter to count the length of the word minus 1,
                       c = word.charAt(counter);                                //then assign character variable c to the character at the counter value, then
                       while ((c == 'A')||(c == 'C')||(c == 'S')||(c == 'L'))       //the while statement checks that character for whether or not it is a "vowel,"
                       {                                                            //
                           counter--;                                               //if so, then counter reassigns value to counter - 1, and then
                           c = word.charAt(counter);                                //reassigns character to the one at the new value
                       }                                                            //
                       String part1 = word.substring(0, counter+1);             //String part1 is generated with substring of word between character 0 and the character at counter - 1
                       String part2 = word.substring((counter+2), lengthOfWord);    //String part2 is generated with substring of word between the character at counter + 2 and the end of the word
                       String newWord = part1 + part2;                              //String newWord is created by putting together parts 1 and 2
                       wordWithSuffix = newWord + suffix;                           //The suffixed word is outputed as the newWord + the suffix
                   }
                   else
                   {
                       counter = (lengthOfWord-1);                                  //if word doesn't fall under any previous conditional statements, then counter is assigned a value equal to the length of
                       c = word.charAt(counter);                                    //the word - 1, and character c is equal to the character at the value counter
                       while ((c != 'A')||(c != 'C')||(c != 'S')||(c != 'L'))       //the while statement checks that character for whether or not is is a "vowel,"
                       {                                                            //
                           counter--;                                               //if so, then counter reassigns value to counter - 1, and then
                           c = word.charAt(counter);                                //reassigns character to the one at the new value
                       }                                                            //
                       String part1 = word.substring(0, counter);                   //String part1 is generated with substring of word between character 0 and the character at the counter value
                       String part2 = word.substring((counter+1), lengthOfWord);    //String part2 is generated with substring of word between the character at counter + 1 and the end of the word
                       String newWord = part1 + part2;                              //String newWord is created by putting together parts 1 and 2
                       wordWithSuffix = newWord + suffix;                           //The suffixed word is outputed as the newWord + the suffix
                   }
               }
           }//end of else
           String suffixedWord = wordWithSuffix;
           return suffixedWord;
       }//end of method

    public static void printFinalData(String line, String word, String suffix, String plural, String wordWithSuffix)    //method which outputs the final data, aka, the plural of word, suffixed word, etc.
    {
        System.out.println("Line Input:           " + line);
        System.out.println("Word:                 " + word);
        System.out.println("Suffix:               " + suffix);
        System.out.println("Plural Of Word:       " + plural);
        System.out.println("New Word With Suffix: " + wordWithSuffix);
        System.out.println();
    }

    public static void main(String[] args) throws IOException //this main method is what tells the other methods when to inititate (which order)
    {
        System.out.println("**********************************");
        System.out.println("* String Project                 *");
        System.out.println("* AP Computer Science A          *");
        System.out.println("* Joshua Nasiatka                *");
        System.out.println("* Winter 2012 (Senior Yr)        *");
        System.out.println("**********************************");
        System.out.println();
        System.out.println("The following is the output:");
        System.out.println();

        //String word = "", suffix = "";


        initiateFile();
        parseFile(pluralizedWord, suffixedWord);

        //plural = makePlural(word);
        makePlural(word);
        //wordWithSuffix = addOnSuffix(word, suffix);
        addOnSuffix(word, suffix);
    }

    public static void parseFile(String pluralizedWord, String suffixedWord) throws IOException
    {
        String line, word, suffix;
        int spaceIndex, length;

        line = reader.readLine(); //reads the input of each line of the external .txt file entitled "vowels.txt"

        while(line != null) //continues to input data until a null is reached in the reader
        {
            spaceIndex = line.indexOf(" ");
            length = line.length();
            word = line.substring(0, spaceIndex);
            suffix = line.substring((spaceIndex+1), length);
            makePlural(word);
            addOnSuffix(word, suffix);
            printFinalData(line, word, suffix, pluralizedWord, suffixedWord);
            line = reader.readLine();
        }
    }
}//end class`
0
nl ja de
Это похоже на 100 строк кода; вам придется сузить его.
добавлено автор G. Bach, источник
Я не знаю, в чем конкретно проблема. Я просто знаю, что это связано с переменными String wordWithSuffix, pluralizedWord и т. Д. В основном методе.
добавлено автор JoshuaNasiatka, источник

2 ответы

Вы говорите об этой строке //plural = makePlural (word); в основном? Ну, конечно, компилятор не может найти символ, и я тоже.

Вам необходимо определить ссылки и создать объекты по мере необходимости для plural , word , wordWithSuffix и т. Д., Прежде чем они будут использованы в main .

0
добавлено
@JoshuaNasiatka Почему строка //private static String line, word, suffix, прокомментирована? это то, что вам нужно
добавлено автор Karthik T, источник
Это проблема. Я не знаю, как
добавлено автор JoshuaNasiatka, источник
Это прокомментировано, потому что я попробовал, и это принесло мне больше ошибок. Большинство комментариев, которые я прокомментировал, это код, который я пытался использовать, но не работал
добавлено автор JoshuaNasiatka, источник

Maybe just do String word = "aWord", "aSuffix"; String plural = makePlural(word); String wordWithSuffix = addOnSuffix(word, suffix);

Я вижу, как вы это делаете, но прокомментировали.

0
добавлено
pro.jvm
pro.jvm
3 503 участник(ов)

Сообщество разработчиков Java Scala Kotlin Groovy Clojure Чат для нач-их: @javastart Наш сайт: projvm.com projvm.ru Наш канал: @proJVM Вакансии: @jvmjobs Конфы: @jvmconf

Java & Co
Java & Co
2 370 участник(ов)

Можно обсуждать с матом и без всё, что касается жабы, вплоть до холиваров. НЕ ИМЕЕТ ОТНОШЕНИЯ К САЙТУ JAVARUSH.RU ПРАВИЛА - https://t.me/javarush/75723 Вакансии сюда - https://telegram.me/joinchat/B7IzvUCnfo6d8t3yIxKguQ По вопросам - @thedude

learn.java
learn.java
1 888 участник(ов)

Чат для начинающих и не только Статистика: https://combot.org/chat/-1001083535868 Основной чат - @jvmchat

Java Underground
Java Underground
169 участник(ов)

https://vk.com/javatutorial

Javanese Questions
Javanese Questions
109 участник(ов)

Чат предназначен для обмена знаниями строго в формате в вопрос-ответ. Тема — Java, Kotlin и Android. Вопрос должен быть предварительно прогуглен, понятно и грамотно сформулирован, помечен хэштегами. Ответ — тем более. Куски кода размером в несколько строк можно писать прямо здесь, для больших кусков кода стоит использовать http://gist.github.com/, http://pastebin.com/, https://codeshare.io/ или любой аналогичный сервис. В некоторых случаях можно прикреплять скриншоты. Стикеры и гифки запрещены. Дополнять и уточнять вопросы и ответы — редактированием исходного сообщения. Обсуждения должны приводить к редактированию вопроса/ответа и удаляться. По хештегам можно искать существующие вопросы и овтеты: #вопрос #ответ #git #generics #java #server #awt #javafx #swing #kotlin #anko #tornadofx #ktor #android #recyclerView #performance #arch #network #permissions #storage #async