Hi wonderful programmers,

I once again need help. First i need to create a class where if the input is a vowel , it returns true and if not it returns false.

i am just learning java, but also just learning classes, methods etc. I know I have to call the method (I understand the method, class, formal param and actual param.

But, I do not know where to start or begin.

From my understanding, I need to first create the method, so it can be called. Is that correct?

2nd, I will need to create the program?

I am confused at this point.

Thanks

You first have to create the Class file(t.e *.java)
then inside you shoud define properties, constructor and methods
after that yiuo should write the main method, in it to make an instance of a object of the class yiou just defined, and whit that object yoiu can call the methods.I hope this is what you wanted to know
Regards,

Hi enicad,

thanks, but now I am even more confused. Here is my code and now I have numerous errors. I know I am probably turning something very simple into something very complicated and hard.

In this code, I am creating the class..but I think I must be confusing the 2. Would you mind looking at it?

/ Program that tells if a letter is a vowel or constant
import java.util.*;
public class isVowel  
{
  static Scanner console = new Scanner(System.in); //creates the new object scanner

 public static void main(String[] args)
 {

 boolean found = true;
 boolean flag = false
 char true;
 true = vowel;
 vowel = a, e, i, o, u;

 System.out.println("Please Enter a Letter: ");
 char = console.nextChar();
        System.out.println();

  {
    if (vowel !found == a && e && i && o && u)
    System.out.println("The character is !found" + vowel (!found a, e, i, o, u));
    else if (vowel != a, e, i, o, u)
    System.out.println("The character is not a !flag" + vowel (!flag a, e, i, o, u);
  }
 } 
}

Thanks

I moved your code around. I think it now does what you wanted.
It actually needs some changes to be good OOP, but I wanted it to still be reconizable to you.

import java.util.*;
public class isVowel 
{
static Scanner console = new Scanner(System.in); //creates the new object scanner
	
	public static void main(String[] args)
	{
		boolean found = false;
	
		String[] vowels = {"a","e","i","o","u","A","E","I","O","U"};
		
		System.out.println("Please Enter a Letter: ");
		String input = console.next();
		System.out.println();
		
		for (String s : vowels)
			if (input.equals(s))
				found = true;
		
		String result = "The input character, " + input;
		if (found)
			result += " is a vowel.";
		else
			result += " is not a vowel!";
		
		System.out.println(result);
	} 
}

Convention says your classes should begin with a capitol letter, but IsVowel is not a great class name.
Maybe the class should be called VowelValidator, or something important sounding like that. isVowel sounds like it should be a method name in your class.
Also, you've got all your code in the main method. Your main should probably be very short. Something like:
VowelValidator vowelValidator = new VowerValidator();
Then maybe take in your input in the constructor, or another method (perhaps in a loop even), calling the method isVowel each time.

I think it would better to write the metod as a static one in a class, as following code shows:

import java.util.*;
public class Vowel{
 private static final String[] vowels 
               = {"a","e","i","o","u","A","E","I","O","U"};
 public static boolean isVowel(String ch){
  for(String v : vowels){
   if(ch.equals(v)){
    return true;
   }
  }

  //if not match return false;
  return false;
 }

 public static void main(String[] args){
  Scanner in = new Scanner(System.in);
  System.out.println("Please enter a character:");
  String ch = in.nextLine();
  boolean isVowel = Vowel.isVowel(ch);
  if(isVowel){
   System.out.println(ch + " is a vowel.");
  } else {
   System.out.println(ch + " is NOT a vowel.");
  }
 }
}
static boolean isVowel( char ch )
  {

    boolean found = false;
    String Vowel = "aeiouAEIOU";

    for( int i=0; i<10; i++ )
      if( Vowel.charAt(i) ==ch)
        found = true;
    return found;
   }

Wouldn't: return (Vowel.indexOf(ch) > -1); be simpler?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.