Question

In Java, write a program that prompts the user to input a sequence of characters and...

In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant. Set the program to discard case.

Sample:

Please enter a string of characters: Little Miss Muffet sat on her tuffet.

The string “Little Miss Muffet sat on her tuffet” contains 20 constants and 10 vowels.

Would you like to enter a new string (y/n)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your answer:

public class VowelConstant{

public static boolean isAVowel(char c){
boolean flag = false;
switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
flag = true;
break;
default:

}
return flag;
}

public static boolean isAConstant(char c){
boolean flag = false;
switch (c) {
case 'a':
break;
case 'e':
break;
case 'i':
break;
case 'o':
break;
case 'u':
break;
default:
flag = true;
break;

}
return flag;
  
}
public static void main(String []args){
  

java.util.Scanner scanner = new java.util.Scanner(System.in);


System.out.print("Please enter a string of characters : ");

  
String inputString = scanner.nextLine();
char[] letters = inputString.replaceAll("\\s","").toCharArray();
int vowelCount = 0;
int constantCount = 0;
for (char c : letters) {
if(isAVowel(c)) {
vowelCount++;
}
if(isAConstant(c)){
constantCount++;
}
}
System.out.println("The string "+ inputString+ " contains " +constantCount+" Consatants "+vowelCount + " Vowels ");
}
}

Add a comment
Know the answer?
Add Answer to:
In Java, write a program that prompts the user to input a sequence of characters and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line wh...

    String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline(), converts the string into Ubbi dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak....

  • Exercise #3: write a Java program that prompts the user to enter a sentence. The program...

    Exercise #3: write a Java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, O, o, I, i) c. the number of characters as numbers or special characters (other than English letters a.z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse: UAEU is the university of the...

  • // Write a program that determines how many of each type of vowel are in an...

    // Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...

  • Write a complete java program that prompts the user for their name and two numbers. The...

    Write a complete java program that prompts the user for their name and two numbers. The correct java methods and parameters must be passed to find the length of the name entered and return “TRUE” if the sum of numbers is even, or FALSE if the sum of numbers is odd: Notes included in the program Sample Program Please enter a name and I will tell you the length of the name entered John Then length of the name John...

  • Java: Assume letters A E O U I as the vowels. Write a program that prompts...

    Java: Assume letters A E O U I as the vowels. Write a program that prompts the user to enter a string and displays the number of vowels and consonants in the string. The same vowels or consonants are counted only once. Use sets in the code.

  • c++ language Write a program that contains the following functions, i. A function isVowel that takes...

    c++ language Write a program that contains the following functions, i. A function isVowel that takes in a character and returns true if it is a vowel and false otherwise ii. A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered. (Use Function in a) to assist you, a sentinel value can be used to specify the end of the user input iii. A function that reads 3 test...

  • Write a program that prompts the user to enter two characters and displays the major and status represented in the characters.

    Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number character 1, 2, 3, 4, which indicates whether a student is a freshman, sophomore, junior, or senior. Suppose the following characters are used to denote the majors: M: MathematicsC: Computer Science T: Testing and Certification

  • Write a C program to “de-vowel” an input string. Assume that the user provides input containing...

    Write a C program to “de-vowel” an input string. Assume that the user provides input containing only the characters a through z (i.e., all lowercase letters). Your program should create an output string that deletes all vowels from the input string, pushing the letters together to fill any gaps. For example, given the input “theturtleandthehare” your code should print out “thtrtlndthhr”. Your program should create an output string from the input string, before printing its output. Sample Input: Enter a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT