can anyone help me do this please i just have to complete where it says the text
ID: 3544939 • Letter: C
Question
can anyone help me do this please i just have to complete where it says the text goes here i typed some stuff below that
this program is to count the vowels Your goal is to write a method getVowels that returns all vowels of a string.
public class Word
{
private String text;
/**
Constructs a word.
@param text the characters in this word
*/
public Word(String text)
{
this.text = text;
}
/**
Tests whether a letter is a vowel
@param letter a string of length 1
@return true if letter is a vowel
*/
public boolean isVowel(String letter)
{
return "aeiouy".contains(letter.toLowerCase());
}
public int countVowels()
{
int i = 0;
int counter = 0;
while (i < text.length())
{
String letter = text.substring(i, i + 1); // the ith letter
//your text goes here.
char ch = str.charAt(i);
if (ch == ' ')
{
i++;
}
return 0;
}
public int countVowelGroups()
{
// Your work here
return 0;
}
public String toString()
{
return text;
}
}
Explanation / Answer
public class Word
{
private String text;
/**
Constructs a word.
@param text the characters in this word
*/
public Word(String text)
{
this.text = text;
}
/**
Tests whether a letter is a vowel
@param letter a string of length 1
@return true if letter is a vowel
*/
public boolean isVowel(String letter)
{
return "aeiouy".contains(letter.toLowerCase());
}
public int countVowels()
{
int i = 0;
int counter = 0;
while (i < text.length())
{
String letter = text.substring(i, i + 1); // the ith letter
if(isVowel(letter))
counter++;
i++;
}
return counter;
}
public int countVowelGroups()
{
// Your work heren
return 0;
}
public String toString()
{
return text;
}
public String getVowels()
{
String str = "";
for(int i=0; i<text.length(); i++)
{
if(isVowel(new String(""+text.charAt(i))))
str = str + text.charAt(i);
}
return str;
}
public static void main(String []args){
Word new_word = new Word("Hello World");
System.out.println("Number of Vowels in Word :"+new_word+ " are "+ new_word.countVowels());
System.out.println("Vowels in Word :"+new_word+ " are "+ new_word.getVowels());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.