Results 1 to 20 of 20

Thread: vowel program

  1. #1
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default vowel program

    • Write a program that includes a method called “Vowel”.
    • This should take a character as input and return whether or not the letter is a vowel.



    package Vowel;
    import java.io.*;
    public class Vowel
    {
    public static void main (String vowel[])throws IOException
    {
    char ch; // sets the char value as ch
    BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); // sets the user input that reads a line/char
    System.out.println ("Enter a Charcter");
    ch = br.readLine().charAt(0);


    if (ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u'|| ch=='A'|| ch=='E'|| ch=='I'|| ch=='O'|| ch=='U') // sets the "if/else" statement
    vowel();// will print the method "vowel()" if the user inputs a vowel
    else
    constent(); // will print the method "constent()" if the user inputs a not vowel
    }

    // setting of methods
    public static void vowel()
    {
    System.out.println ("Entered character is a Vowel");
    }

    public static void constent()
    {
    System.out.println ("Entered character is not a Vowel");
    }

    }

    I'm the only one in my family that knows this stuff so i need a second eye so i wont mass up lol

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: vowel program

    "This should take a character as input and return whether or not the letter is a vowel"
    Your method does not match that description.

    It has no character parameter, and returns nothing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    it does, when the user enters [lets say... K] it returns the constent method and prints out is not a vowel

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    Quote Originally Posted by shad0wblade890 View Post
    it does, when the user enters [lets say... K] it returns the constent method and prints out is not a vowel
    Correct, in the meaning that it returns control to the calling code, not that it returns a value. Its a bit confusing terminology.

    But the important part you are not responding to is that the method indeed does not have a parameter of type char.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: vowel program

    Quote Originally Posted by shad0wblade890 View Post
    it does, when the user enters [lets say... K] it returns the constent method and prints out is not a vowel
    Let's take this one bit at a time:
    "
    • Write a program that includes a method called “Vowel”.
    "
    You need single method called "vowel". The "constent" is unecessary.
    "
    • This should take a character as input and return whether or not the letter is a vowel.
    "
    That method should have a character parameter, so when calling the method you should provide a char to it.
    And it should return a boolean (that's the most obvious way to return whether the char is a vowel).

    Your code might seem to be doing the same sort of thing, but it is not following the requirements.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    can you please give me an example (code line)

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    An example of what? How to create a method with a parameter?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    yes for a char

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: vowel program

    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    I redid it from scratch and i really hope is right way to execute it!!! ive been working non stop for 2 hrs trying to get this right way as she wants it...

    Java Code:
    package Vowel; 
    import java.util.Scanner;
    public class Vowel 
    { 
    public static void main (String[] args)
    	{ 
    char ch; // sets the char value as ch
    Scanner input = new Scanner (System.in); 
    System.out.println ("Enter a Charcter"); 
    ch = input.nextLine().charAt(0);
    
    if (isVowel(ch)== true)
    {
    	System.out.println("IT IS A VOWEL");
    } else
    {
    	System.out.println("IT IS A not VOWEL");
    }
    	}
    
    private static boolean isVowel(char ch) {
    	
    	if (ch=='a'|| ch=='e'|| ch=='i'|| ch=='o'|| ch=='u'|| ch=='A'|| ch=='E'|| ch=='I'|| ch=='O'|| ch=='U')
    		return true;
    	else
    		
    	return false;
    		
    	}
    }
    Last edited by Tolls; 11-20-2013 at 06:29 PM. Reason: Added code tags

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: vowel program

    I haven't run it but it looks like it should work. You could always add a check for Y and print "Sometimes yes, sometimes no." :)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: vowel program

    That's better.
    Though I think your method name is better (method names should generally represent actions), it doesn't actually match your requirements. That's the only real niggle.

    Oh and, when posting code, you should wrap it in [code] tags [/code].
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    what method name should it be then toils? and will i get the full amount of points if i submit it what you think?

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    Quote Originally Posted by shad0wblade890 View Post
    what method name should it be then toils?
    Well the problem description in your initial post states it must be "Vowel". Even though that is a horrible name for a method, you should do what your instructor wants at this point. But you are very correct to want to call it "isVowel".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    thanks to every one! i really appreciate the advice and help! like i said b4 im the only one in my family that knows the tech world in and out so its pretty stressful for me bc i need to figure out these stuff on my own with min help. but im very lucky i found you guys/girls to land a hand on my assignment and improve my programing skills and make friends on the way.

  16. #16
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    I'm curious: are you following a course or are you learning Java on your own here? If you're following a course you are NOT alone, you have your classmates.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  17. #17
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    is a course, but my classmates doesnt community to me idk why...

  18. #18
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    Yeah, that sucks. I hope you can team up with someone else. I would see if you can arrange something like that to improve your chances of success quite a bit. Consider setting up a study group among people you are friendly with.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  19. #19
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: vowel program

    one thing is my speech isnt clear to new people due to birth disable (cerebral palsy) i use a power wheelchair

  20. #20
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: vowel program

    Wow that puts a foot in my mouth. In any case I wouldn't stress about being stuck, just take a tour of some of the other recent "I am new and bla bla" threads in the forum and see that it is quite normal.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  2. Replies: 8
    Last Post: 08-17-2011, 12:15 PM
  3. Replies: 2
    Last Post: 04-02-2011, 01:57 PM
  4. vowel couting
    By aizen92 in forum New To Java
    Replies: 4
    Last Post: 01-12-2011, 10:41 PM
  5. total number of words starting with a vowel
    By somnath6088 in forum New To Java
    Replies: 4
    Last Post: 11-08-2010, 10:52 AM

Posting Permissions

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