Question
here is DemoStringAnalyser.java import java.util.Scanner; public class DemoStringAnalysis { public static void main(String[] args) { String input; // User input char selection; // Menu selection
here is DemoStringAnalyser.java
import java.util.Scanner;
public class DemoStringAnalysis {
public static void main(String[] args) { String input; // User input char selection; // Menu selection // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in);
// Get the string to start out with. System.out.print("Enter a string: "); input = keyboard.nextLine(); do { // Display the menu and get the user's selection. selection = getMenuSelection(); // Act on the selection. switch(selection) { case 'a' : //System.out.println(" Number of vowels: " + //call the countVowels method); //Remember: a static method call needs to be preceeded by the class name break;
case 'b' : //System.out.println(" Number of consonants: " + //call the countConsonats method); break;
case 'c' : //System.out.println(" Number of digits: " + //call the countDigits method); break;
case 'd' : System.out.print("Enter a string: "); input = keyboard.nextLine(); } } while (selection != 'e'); } /** The getMenuSeletion method displays the menu and gets the user's correct choice. @return The user's choice. */ public static char getMenuSelection() { String input; // To hold keyboard input char selection; // The user's selection
// Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Display the menu. System.out.println("a) Count the number of vowels in the string."); System.out.println("b) Count the number of consonats in the string."); System.out.println("c) Count thenumber of digits in the string."); System.out.println("d) Enter another string."); System.out.println("e) Exit the program."); // Get the user's selection. input = keyboard.nextLine(); selection = input.charAt(0); // Validate the input. while (Character.toLowerCase(selection) 'e') { System.out.print("Only enter a, b, c, d, or e: "); input = keyboard.nextLine(); selection = input.charAt(0); } return Character.toLowerCase(selection); } }
Lab 10A: Text Processing Return to: 3 July-9 July P1: String Analyser. Write a StringAnalyser class. The class should have the following static methods: countVowels: returns the number of vowels in a string (given as input parameter), countConsonants: returns the number of consonants (given as input parameter). countDigits: returns the number of digits in the string (given as input parameter) Demonstrate the methods of the StringAnalyser class in a program that performs the following steps: 1. The user is asked to enter a string. 2. The program displays the following menu: a. Count the number of vowels in the string b. Count the number of consonants in the string c.Count the number of digits in the string d. Enter another string . e. Exit the program 3. The program performs the operation selected by the user and repeats until the user selects e, to exit the program. the incomplete code is provided below, just add the method calls Hint: static methods are called like this: ClassName.MethodName), e.g. Math.sqrt(25)) DemoStringAnalyser.javaStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started