Results 1 to 9 of 9

Thread: optiontips.in

  1. #1
    optiontips is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default optiontips.in

    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!

    Java Code:
    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
    Last edited by Eranga; 01-17-2012 at 01:38 PM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: optiontips.in

    Can you let us know what are the errors you end up with?

    And also please use code tags when you are posting code segments again in the forum. Unformatted codes are really hard to read.

  3. #3
    optiontips is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Thumbs up Re: optiontips.in

    --------------------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.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: optiontips.in

    Are you serious with the following?

    Java Code:
    String wordR = word.substring(i, i + 1) + wordR;
    My suggestion is that you must study more about the basis in java. Can you understand what the error you have done in your code?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: optiontips.in

    You must initialize variables before use. That is one of the fundamentals deals with variables in most of the programming languages.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: optiontips.in

    Wrong place. Moving to 'New to Java'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: optiontips.in

    Quote Originally Posted by optiontips View Post
    I tried... and, well, the program works. Java gets it! But, I do have 24 errors.
    If a program has 24 errors (26 actually according to your error message listing) it can't work.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: optiontips.in

    Quote Originally Posted by DarrylBurke View Post
    Wrong place. Moving to 'New to Java'

    db

    I didn't notice it.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default Re: optiontips.in

    Quote Originally Posted by JosAH View Post
    If a program has 24 errors (26 actually according to your error message listing) it can't work.

    kind regards,

    Jos
    If it so I am pretty sure that the salaries in software industry is the lowest.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •