answer.
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]
2 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]2 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
The _______________ domain refers to any endpoint device used by end users, which includes but is not limited to mean any smart
viva [34]
The answer is <span>workstation.   </span>The workstation domain refers to any endpoint device used by end users, which includes but is not limited to mean any smart device in the end user's physical possession and any device accessed by the end user, such as a smartphone, laptop, workstation, or mobile device.
5 0
2 years ago
Define a function compute_gas_volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use
jeyben [28]

Question:

Define a function compute_gas_volume that returns the volume of a gas given parameters pressure, temperature, and moles. Use the gas equation PV = nRT, where P is pressure in Pascals, V is volume in cubic meters, n is number of moles, R is the gas constant 8.3144621 ( J / (mol*K)), and T is temperature in Kelvin.

Answer:

This solution is implemented in C++

double compute_gas_volume(double P, double T, double n){

   double V = 8.3144621 * n * T/P;

   return V;

}

Explanation:

This line defines the function, along with three parameters

double compute_gas_volume(double P, double T, double n){

This calculates the volume

   double V = 8.3144621 * n * T/P;

This returns the calculated volume

   return V;

}

To call the function  from the main, use:

<em>cout<<compute_gas_volume(P,T,n);</em>

<em />

<em>Where P, T and n are double variables and they must have been initialized</em>

5 0
2 years ago
Select the correct text in the passage.
aliina [53]

Answer: When was admitted, hospital authorities recorded his medical history. Then, placed in an ICU where his vital signs were constantly monitored.

Explanation: With the help of computers, medical histories are often kept in the computer for future reference. Machines are connected to computers to record vital signs.

4 0
2 years ago
To finish creating a design for the webpage, use one shape to cut away part of the other. Create a 700 pixel by 700 pixel square
Flauer [41]

Answer:

Explanation:

1. select the rectangle 1 layer and then select the rectangle tool in the left tool bar

2. in the option bar along the top of the UI, select the path operations drop-down and choose subtract front shape.

3. click anywhere on the thin, white rectangle shape on the left side of the document

4. in the create rectangle dialog box, type 700 px for the height and 700 px for the width.

5. click the checkbox that says from center to ensdure the new shape is created from the center of the rectangle 6. click ok

6 0
2 years ago
Int side1;
o-na [289]

Answer:

int width_A, width_B, len_A, len_B;

float rw, rl;

rw = (float)(width_A/width_B);

rl = (float)(len_A/len_B);

if(rw == rl)

printf("They are similar");

else

printf("They are not similar");

Explanation:

The width of the first triangle i call width_A.

The width of the second triangle i call width_B.

The length of the first triangle i call len_A.

The length of the second triangle i call len_B.

The ratio of the width i call rw.

The ratio of the length i call rl.

If rw=rl, the retangles are similar. Otherwise, they are not.

The code is:

int width_A, width_B, len_A, len_B;

float rw, rl;

rw = (float)(width_A/width_B);

rl = (float)(len_A/len_B);

if(rw == rl)

printf("They are similar");

else

printf("They are not similar");

8 0
2 years ago
Other questions:
  • Exercise 6.3 consider memory storage of a 32-bit word stored at memory word 42 in a byte-addressable memory. (a) what is the byt
    14·1 answer
  • Prove that any amount of postage greater than or equal to 64 cents can be obtained using only 5-cent and 17-cent stamps?
    15·1 answer
  • Which type of address is used at the transport layer to identify the receiving application?
    14·1 answer
  • A mistake programmers often make with loops is that they ____.
    15·1 answer
  • You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
    15·2 answers
  • A client is asking for a printing solution that will print three sheets of paper with identical information on each page with a
    13·1 answer
  • Use Excel to develop a regression model for the Consumer Food Database (using the "Excel Databases.xls" file on Blackboard) to p
    13·1 answer
  • A network router connects multiple computers together and allows them to send messages to each other. If two or more computers s
    7·1 answer
  • python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. T
    12·1 answer
  • Given a sorted list of integers, output the middle integer. A negative number indicates the end of the input (the negative numbe
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!