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

ca1358Asked:
Who is Participating?
 
pratap_smsConnect With a Mentor Commented:
The method signature is int getVowelCount(String s)

So you must call like, int vowels = s.getVowelCount("");   //note string in parenthesis
0
 
javaexpertoCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.