I defined the class Letter that has an attribute of type char.
Develop a method called
esVocal()
that returns true or false as appropriate.
My doubt is that the esVocal()
method was not done well, because here I have to use switch
, and I do not know if I do it correctly.
Within each case I put a if
saying if the letter variable is equal to: a, e, i, or, u is vowel, I put in that the state is true so when I enter a vowel, I get true. And in the other case I put the same thing but if the letter variable is different from the vowels, so I get false because if I enter a consonant I have to pull false, but it always pulls me false.
public class Letra {
private char letra;
private boolean valor1 ;
private boolean valor ;
public Letra(char letra) {
this.letra =letra;
this.valor = false;
}
public boolean esVocal(int letra) {
switch(letra) {
case 1 :
if ( letra == 'a' || letra == 'A' ||
letra == 'e' || letra == 'E' ||
letra == 'i' || letra == 'I' ||
letra == 'o' || letra == 'O' ||
letra == 'u' || letra == 'U' ) {
valor = true;
}
break;
case 2:
if ( letra != 'a' || letra != 'A' ||
letra != 'e' || letra != 'E' ||
letra != 'i' || letra != 'I' ||
letra != 'o' || letra != 'O' ||
letra != 'u' || letra != 'U' ) {
valor = false;
}
break;
default : System.out.println("Error!");
break;
}
return this.valor;
}
}
public class PruebaLetra {
public static void main(String[] args) {
Letra l1 = new Letra ('A');
System.out.println(l1.esVocal(2));
}
}