ca1358
asked on
Java Error
Getting Error on this line
int vowels = s.getVowelCount();
System.out.println("The sentence had this many vowels; " + vowels);
Error states
Sentence cannot be applied to ()
Any help would greatly be appreciated.
int vowels = s.getVowelCount();
System.out.println("The sentence had this many vowels; " + vowels);
Error states
Sentence cannot be applied to ()
Any help would greatly be appreciated.
package vowelcounttester;
import java.util.Scanner;
public class VowelCountTester
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String input = in.nextLine();
Sentence s = new Sentence(input);
int vowels = s.getVowelCount();
System.out.println("The sentence had this many vowels; " + vowels);
}
}
********************************************
package vowelcounttester;
public class Sentence
{
public Sentence(String initText)
{
text = initText;
}
public String getText()
{
return text;
}
public int getVowelCount(String s)
{
int vowelCount = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if ( (c == 'A') || (c == 'a')
|| (c == 'E') ||(c == 'e')
|| (c == 'I') || (c == 'i')
|| (c == 'O') || (c == 'o')
|| (c == 'U') || (c == 'U') )
vowelCount++;
vowelCount++;
}
return vowelCount;
}
private String text;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Look at the method declaration:
public int getVowelCount(String s)
So you must pass a String argument when you do this:
int vowels = s.getVowelCount(); //here