Link to home
Start Free TrialLog in
Avatar of ca1358
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.
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;
 
}

Open in new window

Avatar of javaexperto
javaexperto
Flag of Mexico image

The problem is that your method getVowelCount() in the class Sentence, receives one String argument
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
ASKER CERTIFIED SOLUTION
Avatar of pratap_sms
pratap_sms

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial