Results 1 to 15 of 15
  1. #1
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default ugh another method that isn't working

    can any one tell me why I'm getting these errors?

    Java Code:
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:51: <identifier> expected
    System.out.println("Number of vowels= "+isVowel);
                      ^
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:51: illegal start of type
    System.out.println("Number of vowels= "+isVowel);
                       ^
    2 errors
    
    Tool completed with exit code 1
    Java Code:
    import java.util.Scanner;
    
    public class Lab10
    {
    
    
    public static void main(String[] args)
    
    {
    Scanner keyboard= new Scanner(System.in);
    
    //Variables
    int charSequence;
    int vowCount;
    
    
    //User input
    System.out.print("Enter a sequence of characters: ");
    charSequence=keyboard.nextInt();
    
    
    }
    
    public boolean isVowel(int i, char character)
    {
    boolean isVowel;
    char character;
    for(i=0; i<31; i++)
    if(isVowel(character[i]))
    {
    vowCount++;
    }
    else
    {
    return 0;
    }
    }
    
    {	if(character == a|| e|| i|| o|| u)
    {
    
    return true;
    }
    else
    {
    return false;
    }
    
    }
    
    System.out.println("Number of vowels= "+isVowel);
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Your code is not indented and thus hard to read and interpret. If it were indented well, you'd see that the offending code is being called outside of a method or constructor. Moral of the story: indent your code well and consistently as it will help you with your coding and your debugging.

  3. #3
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    Here were the instruction we were given along with the examples if that helps

    Java Code:
    Write a program that prompts the user to input a sequence of characters and outputs the number of vowels. Name the program Lab10.java
    Write a value returning method isVowel that returns the value true if a given character is a vowel and otherwise returns false.
    
    
    Here is a sample run of the program, with user input underlined for emphasis:
    
    Enter a sequence of characters: roopa
    Number of vowels =3
    
    Another run
    
    Enter a sequence of characters: xyz
    Number of vowels =0

  4. #4
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Your code is not indented and thus hard to read and interpret. If it were indented well, you'd see that the offending code is being called outside of a method or constructor.

    thank you I'll do that since it got messed up when I emailed it to my self lol.

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Just one thing I see right off the bat, isVowel is a boolean. Why are you trying to print it in your System.out.println("Number of vowels= " + isVowel);?

    Also what is the point of this snippet?
    Java Code:
    public boolean isVowel(int i, char character)
    {
    boolean isVowel;
    char character;
    for(i=0; i<31; i++)
    if(isVowel(character[i]))
    {
    vowCount++;
    }
    You're looping through a char that isn't an array from what I can see.

    One last thing I noticed is this
    Java Code:
    {	if(character == a|| e|| i|| o|| u)
    I don't really get why there is a opening bracket in front of it.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  6. #6
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    okay I'm going to need a lot more help then I originally thought, once I fixed where the print statement is I got 11 more errors,

    Mainly is doesn't like my a,e,i,o,u statement. And yes the array shouldn't be there.

    screw it here are the errors, any help is welcomed.

    Java Code:
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:21: isVowel(int,char) in Lab10 cannot be applied to ()
    		isVowel();
    		^
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:28: array required, but char found
    		if(isVowel(character[i]))
    		                    ^
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:30: cannot find symbol
    symbol  : variable vowCount
    location: class Lab10
    			vowCount++;
    			^
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:34: incompatible types
    found   : int
    required: boolean
    			return 0;
    			       ^
    
    	               
    
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:47: cannot find symbol
    symbol  : variable isVowel
    location: class Lab10
    System.out.println("Number of vowels = "+isVowel);
    	                                          ^
    C:\Users\Jason\Desktop\cpt-236\Lab10.java:47: package Ssystem does not exist
    	Ssystem.out.println("Number of vowels = "+isVowel);
    	       ^
    11 errors
    
    Tool completed with exit code 1
    I need help with figuring out what I should change that array to and figuring out why it doesn't like the vowels. I think I can take it from there.
    Last edited by jjth39347; 04-16-2011 at 09:59 PM. Reason: fixing errors

  7. #7
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    I believe you are treating Java as if it were a procedural language. I suggest reading up on methods and objects in the tutorial.

    EDIT: And variables too.
    Last edited by ra4king; 04-16-2011 at 09:58 PM.

  8. #8
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    C:\Users\Jason\Desktop\cpt-236\Lab10.java:47: package Ssystem does not exist
    Ssystem.out.println("Number of vowels = "+isVowel);
    Typo, you have Ssystem instead of System.

    C:\Users\Jason\Desktop\cpt-236\Lab10.java:28: array required, but char found
    if(isVowel(character[i]))
    Again, character is not an array.

    I'm not trying to be a douche here, but did you really write this program? You're trying to assign an int to a char, treating a char variable as a char array, you're not even trying to call your isVowel class.

    There's way to many errors to fix, it'd be like rewriting your program.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  9. #9
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Also I just took a look at your a||e||i||o||u statement and you're treating them like variables, not strings.

    You're trying to use a local variable from main, in class isVowel.

    I'm sorry sir but this program might be over your current level of knowlege.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  10. #10
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    This isn't a program I wrote, I'm attempting to fix it for someone who's internet is down and they way she wrote it has me all messed up. This is something I know if she didn't confuse the hell out of me >.< but here is an example that shows I do know how to write methods.

    ugh need some serious methods help

  11. #11
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    I'm just going to rewrite the whole method.

    So please disregard this whole thread. I'll post if I have any real questions
    Last edited by jjth39347; 04-16-2011 at 10:15 PM.

  12. #12
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    We don't need proof of your abilities. However I would suggest that next time you post a program, especially if its for someone else, you take a look at it beforehand and make sure it looks like a runnable program.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  13. #13
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    yea, I'll make sure to do that, sorry for waisting the forums time.

  14. #14
    jjth39347 is offline Member
    Join Date
    Feb 2011
    Posts
    71
    Rep Power
    0

    Default

    okay I got it.

    Java Code:
    
    import java.util.Scanner;
    
    public class Lab10
    {
    
    
    	public static void main(String[] args)
    
    	{
    		Scanner keyboard= new Scanner(System.in); //add keyboard
    	
    		//User input
    		System.out.print("Enter a sequence of characters: ");
    		String character=keyboard.nextLine();
    		int countx=isVowel(character); //call method isVowel
    		System.out.println("Number of vowels is "+countx);
    	}
    
    	public static int isVowel(String character)
    	{
    		//the variables
    		int count = 0;
    		int temp;
    
    		for (int i = 0; i < character.length(); i++) //loop for string
    		{
     		char c = character.charAt(i);
    		if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u') //the vowels
    		count++;
            }
    		return count; //return
    	}
    
    }

  15. #15
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    That looks better :D
    However, I would suggest renaming the method to something like "getVowelCount" because isVowel doesn't make much sense here ;)

Similar Threads

  1. Why isn't my toString method working
    By arri3oi in forum New To Java
    Replies: 7
    Last Post: 12-13-2010, 05:34 AM
  2. dispose() method not working
    By R&R in forum New To Java
    Replies: 19
    Last Post: 11-15-2010, 01:46 AM
  3. Thread Stop() method not working
    By charan reddy in forum Threads and Synchronization
    Replies: 18
    Last Post: 10-03-2009, 03:01 PM
  4. Can't find out how to get this method working :)
    By Shadaw in forum Java Applets
    Replies: 2
    Last Post: 12-29-2008, 05:35 PM
  5. makeButton method not working
    By ljk8950 in forum AWT / Swing
    Replies: 8
    Last Post: 08-10-2008, 10:20 PM

Posting Permissions

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