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
A student is reading a book for language arts. She has to finish three chapters by class tomorrow, because there will be a quiz.
Jobisdone [24]

Answer:

Distracted..?

8 0
3 years ago
Read 2 more answers
Genres are useful for many reaseons. What are some explanations you can think of for how genres can be useful to players, game d
elena-14-01-66 [18.8K]
  • Genres are used in Readers as well as writers.
  • By using genre patterns in writers it has been accepted by readers for accomplishing their purposes.
  • Genres allow both writers and readers to establish a working relationship between each other.
  • Both writers and readers are required for gamers and game publishers.
  • So Genres are very useful to them.
7 0
3 years ago
Which spreadsheet feature could the scholarship committee use to locate applicants who meet the criteria?
Radda [10]

Answer:

H8

Explanation:

4 0
3 years ago
What X coordinate does the center of a game begin at?
kotegsom [21]

A. 0

I am not entirely sure, I am not much of a coder(well I am but I don’t code often) so I hope this helps!

5 0
3 years ago
A Turing machine with stay put instead of left is similar to an ordinary Turing machine, but the transition function has the for
sasho [114]

Answer:

The class of language the machines recognise is Regular Language (See Explanation Below)

Explanation:

Given

Form δ : Q × Γ → Q × Γ × {R, S}

From the above transition form, it can be seen that the machine cannot read square symbols passed to it.

Regarding the square the machine is currently reading, there are multiple movement of S and it shouldn't be so because any number of the multiple movement can be simulated by exactly one movement of S.

As stated earlier that sequence of moves can be simulated by just one movement.

Let R = the movement

This means the machine can only use right move efficiently.

With this, we can say that the machine only read input string.

This is a characteristic of DFA (Deterministic Finite Automata).

With this, we can conclude that some DFAs will simulate the Turing machine and that they only read regular language.

5 0
3 years ago
Other questions:
  • Modern operating systems decouple a process address space from the machine’s physical memory. List two advantages of this design
    15·1 answer
  • Race conditions are possible in many computer systems. Consider a banking system with two methods: deposit(amount) and withdraw(
    14·1 answer
  • Good afternoon guys !!!
    14·2 answers
  • i got a set of headphones and when i plug them into my speakers the right side only works how do i fix the left side of them
    12·1 answer
  • The best way to insert an existing Excel chart into a document is to
    8·1 answer
  • Suppose that a program asks a user to enter multiple integers, either positive or negative, to do some calculation. The data ent
    13·1 answer
  • 50 POINTS
    6·1 answer
  • Give five example of secondary storage device, stating their function and storage capacity​
    6·1 answer
  • If you are connected to a network that uses DHCP, and you need to terminate your Windows workstation's DHCP lease, which command
    12·1 answer
  • Monica is writing a paper, and it needs to contain a certain amount of words. What Word Online feature can she use?IndentingProo
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!