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 5 of 5

Thread: Where are all the symbols!? Poor Java can't find them... :(

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Where are all the symbols!? Poor Java can't find them... :(

    Hello! For my computer science class, I have to convert a program with global variables to a program with all instantiated variables. I tried... and, well, the program works. Java gets it! But, I do have 24 errors.

    Here is my new code:
    //Note: You need to change the input file to the one on your computer!
     
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.HashSet;
     
    public class VowlezRUs {
    		//method variables
    			private static FileInputStream inFile;
    			private static InputStreamReader inReader;
    			private static BufferedReader reader;
     
    public static void main (String args[]) throws IOException
    {
    	//Methods
    	initFile();
    	doStuff();
    	inFile.close();
    }
     
    public static void initFile() throws IOException
    {
    	//Data Input
    		inFile = new FileInputStream ("D:\\My Documents...\\blooby.txt");
    		inReader = new InputStreamReader (inFile);
    		reader = new BufferedReader (inReader);
    }
     
    public static void doStuff() throws IOException
    {
    	int leftmostIndex;
    	//Line can't be null for loop to execute
    		String line = "start";
    		while (line != null) {
    			//Data conversion into strings
    			line = reader.readLine();
    			if (line == null)
    				{
    				break;
    				}
     
    	StringTokenizer strTkn;
    	strTkn = new StringTokenizer(line);
    	String word = strTkn.nextToken();
    	String suffix = strTkn.nextToken();
     
    	//TEST
    	//System.out.print(word);
     
    	//add vowels to set for comparing
    		HashSet vowels = null;
    		vowels = new HashSet();
    		vowels.add("A");
    		vowels.add("C");
    		vowels.add("S");
    		vowels.add("L");
     
    	//TEST
    	//System.out.println(word);
     
    	//Set output variables...
    		String wordPlural = word;
    		String wordSuffix = word;
     
    	//reverse word for testing
    		for (int i = 0; i < word.length(); i++)
    			{
    			String wordR = word.substring(i, i+1) + wordR;
    			}
     
    	//reverse suffix for testing
    		for (int i = 0; i < suffix.length(); i++)
    			{
    			String suffixR = suffix.substring(i, i+1) + suffixR;
    			}
     
    	//TEST
    	//System.out.println(wordR);
     
    	//if wordR ends in a consonant
    		if (vowels.contains(wordR.substring(0,1)) == false) {
     
    			//if wordR ends in more than one consonant
    			if (vowels.contains(wordR.substring(1,2)) == false) {
    				//Double the last letter, then add ‘H’
    				String lastLetter = wordR.substring(0,1);
    				String wordPlural = wordR.concat(lastLetter);
    				wordPlural = wordR.concat("H");
    				System.out.print("plural: " + wordR);
     
    				//if suffix ends in a consonant
    				if (vowels.contains(suffixR.substring(1,2)) == false) {
    					//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    					String vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    					vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    					String wordSuffix = wordSuffix.substring(0, leftmostIndex);
    					wordSuffix = wordSuffix.concat(vowelSeries);
    					wordSuffix = wordSuffix.concat(suffix);
    					System.out.println("Suffix: " + wordSuffix);
     
    				//if suffix ends in vowel
    				}else{
    					//add the first letter of the suffix, then add the suffix
    					String firstLetter = suffix.substring(0,1);
    					wordSuffix = suffix.concat(firstLetter).concat(word);
    					System.out.println("Suffix: " + wordSuffix);
    					}
     
     
    				//if wordR ends in 1 consonant
    				}else{
    					//original string
    					System.out.println("Original String: " + line);
    					//add “GH”
    					wordPlural = word.concat("GH");
    					System.out.println("Plural: " + wordPlural);
    					//add the suffix
    					wordSuffix = word.concat(suffix);
    					System.out.println("Suffix: " + wordSuffix);
    				}
     
    				//if wordR ends in a vowel
    				}else{
    					//if wordR ends in more than 1 vowel
    					if (vowels.contains(wordR.substring(1,2)) == true) {
    					//Index of leftmost of vowel series
    						for (int i = 0; i < wordR.length(); i++)
    							{
    							if (vowels.contains(wordR.substring(i, i+1)))
    							{
    							leftmostIndex++;
    							}else{
    							break;
    							}
    							}
     
     					//original String
    					System.out.println("Original String: " + line);
     
    					//double the last letter, then add ‘H’
    					lastLetter = wordR.substring(0,1);
    					wordPlural = word;
    					wordPlural = wordPlural.concat(lastLetter);
    					wordPlural = wordPlural.concat("H");
    					System.out.println("Plural: " + wordPlural);
     
    						//if suffix ends in consonant
    						if (vowels.contains(suffixR.substring(1,2)) == false) {
    							//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    							vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    							vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    							wordSuffix = wordSuffix.substring(0, leftmostIndex);
    							wordSuffix = wordSuffix.concat(vowelSeries);
    							wordSuffix = wordSuffix.concat(suffix);
    							System.out.println("Suffix: " + wordSuffix);
    							//if suffix ends in vowel
    						}else{
    							//add the first letter of the suffix, then add the suffix
    							firstLetter = suffix.substring(0,1);
    							wordSuffix = suffix.concat(firstLetter).concat(word);
    							System.out.println("Suffix: " + wordSuffix);
    							}
     
    					}else{
    						System.out.println("Original String: " + line);
    						//drop the final vowel and add ‘G’
    						wordPlural = word.substring(0, word.length()-1);
    						wordPlural = wordPlural.concat("G");
    						System.out.println("Plural: " + wordPlural);
     
    						//if suffix ends in consonant
    						if (vowels.contains(suffixR.substring(1,2)) == false) {
    							//add the first letter of the suffix and then add the suffix
    							firstLetter = suffix.substring(0,1);
    							wordSuffix = wordSuffix.concat(firstLetter);
    							wordSuffix = wordSuffix.concat(suffix);
    							System.out.println("Suffix: " + wordSuffix);
     
    						//if suffix ends in vowel
    						}else{
    							//drop the first letter of the suffix and add the rest of the suffix
    							suffix = suffix.substring(1, suffix.length());
    							wordSuffix = word;
    							wordSuffix = word.concat(suffix);
    							System.out.println("Suffix: " + wordSuffix);
    }
    }
    } //line
     
    } //massive while loop
    } //doStuff()
     
    } //class VowelsRU

    And here is the original code:
    /*--------------------------------
        Name: Caitlin Connerney
        School: St. George's School
        Course: AP Computer Science
        Project: Vowels R Us
     ---------------------------------*/
     
    //Note: You need to change the input file to the one on your computer!
     
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.HashSet;
     
    public class VowelsRUs {
    		//method variables
    			private static FileInputStream inFile;
    			private static InputStreamReader inReader;
    			private static BufferedReader reader;
    			private static StringTokenizer strTkn;
     
    		//string variables
    			private static String line, suffix, suffixR, word, wordR, wordPlural, wordSuffix;
    			private static String firstLetter, lastLetter, testLetter, vowelSeries, consonantSeries;
     
    		//number variables
    			private static int leftmostIndex;
     
    		//set variables
    			private static HashSet vowels = null;
     
     
    public static void main (String args[]) throws IOException
    {
    	//Methods
    	initFile();
    	doStuff();
    	inFile.close();
    }
     
    public static void initFile() throws IOException
    {
    	//Data Input
    		inFile = new FileInputStream ("D:\\My Documents\\Senior\\APCompsci\\VHS APCS\\Data\\blooby.txt");
    		inReader = new InputStreamReader (inFile);
    		reader = new BufferedReader (inReader);
    }
     
    public static void doStuff() throws IOException
    {
    	//Line can't be null for loop to execute
    		line = "start";
    		while (line != null) {
     
    	//Data conversion into strings
    		line = reader.readLine();
    		if (line == null)
    			{
    			break;
    			}
     
    	strTkn = new StringTokenizer(line);
    	word = strTkn.nextToken();
    	suffix = strTkn.nextToken();
     
    	//TEST
    	//System.out.print(word);
     
    	//add vowels to set for comparing
    		vowels = new HashSet();
    		vowels.add("A");
    		vowels.add("C");
    		vowels.add("S");
    		vowels.add("L");
     
    	//TEST
    	//System.out.println(word);
     
    	//Set output variables...
    		wordPlural = word;
    		wordSuffix = word;
     
    	//reverse word for testing
    		for (int i = 0; i < word.length(); i++)
    			{
    			wordR = word.substring(i, i+1) + wordR;
    			}
     
    	//reverse suffix for testing
    		for (int i = 0; i < suffix.length(); i++)
    			{
    			suffixR = suffix.substring(i, i+1) + suffixR;
    			}
     
    	//TEST
    	//System.out.println(wordR);
     
    	//if wordR ends in a consonant
    		if (vowels.contains(wordR.substring(0,1)) == false) {
     
    	//TEST
    	//System.out.print("c ");
     
     
    	//if wordR ends in more than one consonant
    		if (vowels.contains(wordR.substring(1,2)) == false) {
     
    	//TEST
    	//System.out.print("2c ");
     
    	//Double the last letter, then add ‘H’
    		lastLetter = wordR.substring(0,1);
    		wordPlural = wordR.concat(lastLetter);
    		wordPlural = wordR.concat("H");
    		System.out.print("plural: " + wordR);
     
    	//if suffix ends in a consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    		vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    		vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    		wordSuffix = wordSuffix.substring(0, leftmostIndex);
    		wordSuffix = wordSuffix.concat(vowelSeries);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
     
    	//if suffix ends in vowel
    		}else{
    	//add the first letter of the suffix, then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = suffix.concat(firstLetter).concat(word);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
     
    	//if wordR ends in 1 consonant
    		}else{
     
    	//TEST
    	//System.out.print("1c ");
     
    	//original string
    		System.out.println("Original String: " + line);
    		//add “GH”
    		wordPlural = word.concat("GH");
    		System.out.println("Plural: " + wordPlural);
    		//add the suffix
    		wordSuffix = word.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
    	//if wordR ends in a vowel
    		}else{
     
    	//if wordR ends in more than 1 vowel
    		if (vowels.contains(wordR.substring(1,2)) == true) {
     
    	//TEST
    	//System.out.println("2v ");
     
    	//Index of leftmost of vowel series
    		for (int i = 0; i < wordR.length(); i++)
    			{
    			if (vowels.contains(wordR.substring(i, i+1)))
    			{
    			leftmostIndex++;
    			}else{
    			break;
    			}
    			}
     
    	//test
    	//System.out.println(leftmostIndex);
     
    	//original String
    		System.out.println("Original String: " + line);
     
    	//double the last letter, then add ‘H’
    		lastLetter = wordR.substring(0,1);
    		wordPlural = word;
    		wordPlural = wordPlural.concat(lastLetter);
    		wordPlural = wordPlural.concat("H");
    		System.out.println("Plural: " + wordPlural);
     
    	//if suffix ends in consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    		vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    		vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    		wordSuffix = wordSuffix.substring(0, leftmostIndex);
    		wordSuffix = wordSuffix.concat(vowelSeries);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    	//if suffix ends in vowel
    		}else{
    	//add the first letter of the suffix, then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = suffix.concat(firstLetter).concat(word);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
    	}else{
     
    	//TEST
    	//System.out.println("v ");
     
    		System.out.println("Original String: " + line);
     
    	//drop the final vowel and add ‘G’
    		wordPlural = word.substring(0, word.length()-1);
    		wordPlural = wordPlural.concat("G");
    		System.out.println("Plural: " + wordPlural);
     
    	//if suffix ends in consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//add the first letter of the suffix and then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = wordSuffix.concat(firstLetter);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
     
    	//if suffix ends in vowel
    	}else{
    	//drop the first letter of the suffix and add the rest of the suffix
    		suffix = suffix.substring(1, suffix.length());
    		wordSuffix = word;
    		wordSuffix = word.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    }
    }
    } //line
     
    } //massive while loop
    } //doStuff()
     
    } //class VowelsRU

    So you can see the string variables and such that I tried to incorporate into the new code, but I can't figure out what else I can do to get rid of the errors. Here is my error list, should you also require that to assist me:

    --------------------Configuration: VowlezRUs - JDK version 1.7.0_02 <Default> - <Default>--------------------
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:88: error: cannot find symbol
    		if (vowels.contains(wordR.substring(0,1)) == false) {
    		                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:91: error: cannot find symbol
    			if (vowels.contains(wordR.substring(1,2)) == false) {
    			                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:93: error: cannot find symbol
    				String lastLetter = wordR.substring(0,1);
    				                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:94: error: wordPlural is already defined in doStuff()
    				String wordPlural = wordR.concat(lastLetter);
    				       ^
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:94: error: cannot find symbol
    				String wordPlural = wordR.concat(lastLetter);
    				                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:95: error: cannot find symbol
    				wordPlural = wordR.concat("H");
    				             ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:96: error: cannot find symbol
    				System.out.print("plural: " + wordR);
    				                              ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:99: error: cannot find symbol
    				if (vowels.contains(suffixR.substring(1,2)) == false) {
    				                    ^
      symbol:   variable suffixR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:103: error: wordSuffix is already defined in doStuff()
    					String wordSuffix = wordSuffix.substring(0, leftmostIndex);
    					       ^
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:132: error: cannot find symbol
    					if (vowels.contains(wordR.substring(1,2)) == true) {
    					                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:134: error: cannot find symbol
    						for (int i = 0; i < wordR.length(); i++)
    						                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:136: error: cannot find symbol
    							if (vowels.contains(wordR.substring(i, i+1)))
    							                    ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:148: error: cannot find symbol
    					lastLetter = wordR.substring(0,1);
    					^
      symbol:   variable lastLetter
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:148: error: cannot find symbol
    					lastLetter = wordR.substring(0,1);
    					             ^
      symbol:   variable wordR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:150: error: cannot find symbol
    					wordPlural = wordPlural.concat(lastLetter);
    					                               ^
      symbol:   variable lastLetter
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:155: error: cannot find symbol
    						if (vowels.contains(suffixR.substring(1,2)) == false) {
    						                    ^
      symbol:   variable suffixR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:157: error: cannot find symbol
    							vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    							^
      symbol:   variable vowelSeries
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:158: error: cannot find symbol
    							vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    							^
      symbol:   variable vowelSeries
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:158: error: cannot find symbol
    							vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    							                                       ^
      symbol:   variable vowelSeries
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:158: error: cannot find symbol
    							vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    							              ^
      symbol:   variable vowelSeries
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:160: error: cannot find symbol
    							wordSuffix = wordSuffix.concat(vowelSeries);
    							                               ^
      symbol:   variable vowelSeries
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:166: error: cannot find symbol
    							firstLetter = suffix.substring(0,1);
    							^
      symbol:   variable firstLetter
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:167: error: cannot find symbol
    							wordSuffix = suffix.concat(firstLetter).concat(word);
    							                           ^
      symbol:   variable firstLetter
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:179: error: cannot find symbol
    						if (vowels.contains(suffixR.substring(1,2)) == false) {
    						                    ^
      symbol:   variable suffixR
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:181: error: cannot find symbol
    							firstLetter = suffix.substring(0,1);
    							^
      symbol:   variable firstLetter
      location: class VowlezRUs
    D:\My Documents\JCreator LE\MyProjects\VowlezRUs\src\VowlezRUs.java:182: error: cannot find symbol
    							wordSuffix = wordSuffix.concat(firstLetter);
    							                               ^
      symbol:   variable firstLetter
      location: class VowlezRUs
     
    26 errors
     
    Process completed.

    Also, here is what consists of the text file I'm using for the input stream:
    XQAC ZVM
    PDAE AV
    SNIC SY
    AAAB BB

    Essentially, I am given a fictional word, and need to add a fictional suffix to the end. My main problem with the program, as you can see, is that I am having trouble declaring variables properly. If you would like the assignment prompt, please say so, as I would be happy to offer any documents that would help you help me!

    Thank you in advance!


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

    Default Re: Where are all the symbols!? Poor Java can't find them... :(

    A few things to keep in mind:

    1. You must declare and initialize your variables before you use them.

    2. A local variable's scope exists entirely inside of the block it was declared in. When you enter that block, that variable is "created" and comes into scope. When you leave that block, that variable goes out of scope and can no longer be used. Note that when you re-enter the block, even though the variable may have the same name, it must be created because the old variable has gone out of scope and no longer exists.

    3. Scopes can nest. So variables declared in a block is accessible from every block nested inside of the block it was declared in as long as it follows rule 1.

    I think these rules should be able to solve every one of your compile errors.

    For example, here's your first compiler error:

    for (int i = 0; i < word.length(); i++)
    			{
    			String wordR = word.substring(i, i+1) + wordR;
    			}

    Here, on each iteration through the for loop you're re-creating the variable wordR, then trying to initialize it to some string + wordR. But what is wordR? You haven't initialized it yet for that iteration, and whatever variable existed prior no longer exists. So what is being add to the end word.substring(i,i+1)? The compiler has no idea, and that's why it's complaining. So how should you fix this problem? Hint: take a look at rule 3 and rule 1.

    Take a look at the compiler output and go to the lines it's complaining about. Try to apply the above rules and see if you can't figure out how to solve the other compiler errors.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    coffecupcake (January 16th, 2012)

  4. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Where are all the symbols!? Poor Java can't find them... :(

    Thank you, I will try looking at all of these and see where I get. I got it down to one error, but when I fix that one error, another pops up somewhere! Frustrating.

    Thanks again!

  5. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Where are all the symbols!? Poor Java can't find them... :(

    I've been trying to fix this but it keeps telling me that my variables have not been initialized. I'm getting very confused and frustrated.. Help?
    Here's my attempt at fixing the code...
    //Note: You need to change the input file to the one on your computer!
     
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.HashSet;
     
    public class VowelsWeAre {
    		//method variables
    			private static FileInputStream inFile;
    			private static InputStreamReader inReader;
    			private static BufferedReader reader;
    			private static StringTokenizer strTkn;
     
    public static void main (String args[]) throws IOException
    {
    	//Methods
    	initFile();
    	doStuff();
    	inFile.close();
    }
     
    public static void initFile() throws IOException
    {
    	//Data Input
    		inFile = new FileInputStream ("D:\\My Documents\\Senior\\APCompsci\\VHS APCS\\Data\\blooby.txt");
    		inReader = new InputStreamReader (inFile);
    		reader = new BufferedReader (inReader);
    }
     
    public static void doStuff() throws IOException
    {
    		String line = "start";					//Line can't be null for loop to execute
    		while (line != null){
    			line = reader.readLine();			//Data conversion into strings
    					if (line == null)
    						{
    						break;
    						}
     
    			strTkn = new StringTokenizer(line);
    			String word = strTkn.nextToken();
    			String suffix = strTkn.nextToken();
     
    			HashSet vowels = null;
    			vowels = new HashSet();		//add vowels to set for comparing
    			vowels.add("A");
    			vowels.add("C");
    			vowels.add("S");
    			vowels.add("L");
     
    										//TEST
    										//System.out.println(word);
    			String wordPlural = word;
    			String wordSuffix = word;			//Set output variables...
     
    			String wordR, suffixR, firstLetter,lastLetter, vowelSeries;
    			int leftmostIndex;
     
    	//if wordR ends in a consonant
    		if (vowels.contains(wordR.substring(0,1)) == false) {
     
    											//TEST
    											//System.out.print("c ");
     
     
    		//if wordR ends in more than one consonant
    		if (vowels.contains(wordR.substring(1,2)) == false) {
    				lastLetter = wordR.substring(0,1);
    				wordPlural = wordR.concat(lastLetter);	//Double the last letter, then add ‘H’
    				wordPlural = wordR.concat("H");
    				System.out.print("plural: " + wordR);
     
    	//if suffix ends in a consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    		vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    		vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    		wordSuffix = wordSuffix.substring(0, leftmostIndex);
    		wordSuffix = wordSuffix.concat(vowelSeries);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
     
    	//if suffix ends in vowel
    		}else{
    	//add the first letter of the suffix, then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = suffix.concat(firstLetter).concat(word);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
     
    	//if wordR ends in 1 consonant
    		}else{
     
    	//TEST
    	//System.out.print("1c ");
     
    	//original string
    		System.out.println("Original String: " + line);
    		//add “GH”
    		wordPlural = word.concat("GH");
    		System.out.println("Plural: " + wordPlural);
    		//add the suffix
    		wordSuffix = word.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
    	//if wordR ends in a vowel
    		}else{
     
    	//if wordR ends in more than 1 vowel
    		if (vowels.contains(wordR.substring(1,2)) == true) {
     
    	//TEST
    	//System.out.println("2v ");
     
    	//Index of leftmost of vowel series
    		for (int i = 0; i < wordR.length(); i++)
    			{
    			if (vowels.contains(wordR.substring(i, i+1)))
    			{
    			leftmostIndex++;
    			}else{
    			break;
    			}
    			}
     
    	//test
    	//System.out.println(leftmostIndex);
     
    	//original String
    		System.out.println("Original String: " + line);
     
    	//double the last letter, then add ‘H’
    		lastLetter = wordR.substring(0,1);
    		wordPlural = word;
    		wordPlural = wordPlural.concat(lastLetter);
    		wordPlural = wordPlural.concat("H");
    		System.out.println("Plural: " + wordPlural);
     
    	//if suffix ends in consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//drop the leftmost letter of the final sequence of either vowels or consonants, then add the suffix
    		vowelSeries = word.substring(word.length()-leftmostIndex, word.length());
    		vowelSeries = vowelSeries.substring(1, vowelSeries.length());
    		wordSuffix = wordSuffix.substring(0, leftmostIndex);
    		wordSuffix = wordSuffix.concat(vowelSeries);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    	//if suffix ends in vowel
    		}else{
    	//add the first letter of the suffix, then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = suffix.concat(firstLetter).concat(word);
    		System.out.println("Suffix: " + wordSuffix);
    		}
     
    	}else{
     
    	//TEST
    	//System.out.println("v ");
     
    		System.out.println("Original String: " + line);
     
    	//drop the final vowel and add ‘G’
    		wordPlural = word.substring(0, word.length()-1);
    		wordPlural = wordPlural.concat("G");
    		System.out.println("Plural: " + wordPlural);
     
    	//if suffix ends in consonant
    		if (vowels.contains(suffixR.substring(1,2)) == false) {
    	//add the first letter of the suffix and then add the suffix
    		firstLetter = suffix.substring(0,1);
    		wordSuffix = wordSuffix.concat(firstLetter);
    		wordSuffix = wordSuffix.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
     
    	//if suffix ends in vowel
    	}else{
    	//drop the first letter of the suffix and add the rest of the suffix
    		suffix = suffix.substring(1, suffix.length());
    		wordSuffix = word;
    		wordSuffix = word.concat(suffix);
    		System.out.println("Suffix: " + wordSuffix);
    }
    }
    } //line
     
    } //massive while loop
    } //doStuff()
     
    } //class VowelsRU

  6. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    660
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Where are all the symbols!? Poor Java can't find them... :(

    Here's your declaration of leftmostIndex:
    int leftmostIndex;

    Now with that in mind, when you use that variable, what do you expect to get? what value do you need it to be?
    It's saying you need to initialise the variable, to a default value.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

Similar Threads

  1. Please help me to find a sample application devloped using Java 1.7
    By kondapalli_kumar in forum Java Theory & Questions
    Replies: 1
    Last Post: September 9th, 2011, 10:12 AM
  2. how to find stack size in java
    By aditiya in forum Java Theory & Questions
    Replies: 6
    Last Post: July 8th, 2011, 06:29 AM
  3. Replies: 3
    Last Post: February 23rd, 2011, 12:27 AM
  4. Replies: 7
    Last Post: November 23rd, 2010, 10:03 PM
  5. [SOLVED] How to a set java class path?
    By captjade in forum Java Theory & Questions
    Replies: 1
    Last Post: March 10th, 2009, 06:40 AM