1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
andre [41]
3 years ago
13

Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the n

umber of vowels in the string, and another method that returns the number of consonants in the string. (Spaces count as neither vowels nor consonants and should be ignored.) Demonstrate the 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:
1. Count the number of vowels in the string
2. Count the number of consonants in the string
3. Count both the vowels and consonants in the string
4. Enter another string
5. Exit the program
Computers and Technology
1 answer:
mote1985 [20]3 years ago
4 0

Answer:

import java.util.Scanner;

public class VowelsAndConsonantsDemo {

   /**

   The printMenu methods displays a menu to the user

    */

   public static void printMenu() {

       System.out.println("Please select an option: ");

       System.out.println();

       System.out.print("a. Count the number of vowels in the string.\n"

               + "b. Count the number of consonants in the string.\n"

               + "c. Count both the vowels and consonants in the string.\n"

               + "d. Enter another string.\n"

               + "e. Exit the program\n");

   }

   public static void main(String[] args) {

       String input;      // to hold the user's input

       String option;     // to hold the user's input

       char choice;       // to hold a single character

       char exit;         // user chooses 'e' to exit the program

       char letter;       //the Y or N from the user's decision to exit

       // create a Scanner object to read keyboard input.

       //  Scanner keyboard = new Scanner(System.in);

       Scanner keyboard;

       do {

           keyboard = new Scanner(System.in);

           // ask user to enter string

           System.out.print("Enter a string: ");

           input = keyboard.nextLine();

           input = input.toLowerCase();

           System.out.println();

           printMenu();

           option = keyboard.nextLine();

           choice = option.charAt(0);

           VowelsAndConsonants words = new VowelsAndConsonants(input);

           switch (choice) {

               case 'a':

               case 'A':

                   System.out.println("Number of Vowels: " + words.getVowels());

                   break;

               case 'b':

               case 'B':

                   System.out.println("Number of Consonants: " + words.getConsonants());

                   break;

               case 'c':

               case 'C':

                   System.out.println("Number of Vowels & Consonants: " + words.getConsonants()

                           + words.getVowels());

                   break;

               case 'd':

               case 'D':

                   System.out.println("Enter a string: ");

                   break;

               case 'e':

               case 'E':

                   System.exit(0);

                   break;

               default:

                   System.out.println("You did not enter a valid choice.");

           }

           //

           // keyboard.nextLine();    //consumes the new line character after the choice

           // String answer = keyboard.nextLine();

           // letter = answer.charAt(0);

       } while (true);

   }

}

You might be interested in
You have observed that Alexander Rocco Corporation uses Alika’s Cleaning Company for its janitorial services. The company’s
Rzqust [24]

Answer:

Explanation:

Relevance of Thrown Items:

  •    The thrown items mainly consist of the Windows NT training kit, outdated magazines and some written notes, etc. All these things can be used in the company for training the fresh talent.
  •    These things must be used for the purpose of training fresh people and the things like programs written in HTML must not be dumped like this because they consists of the raw code which can be harmful if gotten into wrong hands.
  •    Hence, the information like this must be taken care of seriously as these can be loopholes into companies down.
  •    Rest of the things like food wrappers, empty bottles, resume copies are all worthless to the company and can be thrown into the dump as soon as possible.The business cards must also be thrown if not important.

Recommendation To Management:

  •    The management must take these things seriously and must double check the company properties before throwing them into dump. There must be a committe build to check the things that are been going directly to the dump.
  •    They must have the responsibility for checking the things before going to the dump and must filter all the important things from the garbage back to the shelves of the office.
  • Hence, these things must be taken care of so that no harm is to be done to the company.

cheers i hope this helped !!

5 0
4 years ago
What is a good principle to implement when you find yourself attempting to
Maurinko [17]

its less is more A

to much could make it really bad

5 0
4 years ago
Does anyone know how to code
Bumek [7]

Answer:

yeah u just CODE

Explanation:

MARK BRAINLIEST PLEASE

THANK U!!!!!

3 0
3 years ago
Read 2 more answers
What information on social networking sites could be used to discriminate against a potential employee
NISA [10]

the answer on plato is b

political affiliations

3 0
3 years ago
3. Windows that are viewed as Web pages have<br> sections. **
tankabanditka [31]

Answer:

when the when the when the add the when are you is id god his gay for your top off jack dafe cafe read line green red whats the answer

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • All resources are limited. Which of the following is NOT a resource?
    11·1 answer
  • Consider an array of size nine with the numbers in the following order: 40, 60, 20, 80, 70, 90, 30, 10, 50. (a) Create the heap
    7·1 answer
  • You can run a macro by:
    10·1 answer
  • To type a small letter "z", you would use the right little finger. (5 points)True False
    9·1 answer
  • Which of the following identifies the patterns used for each data series in a chart?
    12·1 answer
  • Brainliest
    7·1 answer
  • Look out for users with this photo.
    15·2 answers
  • 9.3 Code Practice
    13·2 answers
  • If a machine cycle is 2 nanoseconds , how many machine cycles occur each second?
    7·1 answer
  • Discuss the what is software development​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!