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]
1 year 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]1 year 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
Multiple boolean expressions can be combined by using a logical operator to create ________ expressions.
Licemer1 [7]
<span>Boolean expressions can be combined by using a logical operator to create compound expressions. A boolean expression is an expression that takes into account and evaluates specific data, which is in the form of true and/or false. A compound expression is merely a statement of expressions.</span>
8 0
1 year ago
The attack in which the attacker sends a forged packet with the same source IP address and destination IP address in which the v
Sergeeva-Olga [200]

Answer:

TEARDROP

Explanation:

Teardrop is a form of attack in which the attacker sends a forged packet with the same source IP address and destination IP address in which the victim may be tricked into sending messages to and from itself .

Teardrop attack also involves sending fragmented packets to a target machine in which the victim is been tricked into sending messages to and from itself. One of the fields in an IP header is the “fragment offset” field, indicating the starting position of the data contained in a fragmented packet relative to the data in the original packet.

7 0
2 years ago
A(n) _________ is a document containing an organization's policies for the ethical, secure, and appropriate use of computing res
blsea [12.9K]

Answer: a) acceptable use policy

Explanation:

  • Acceptable use policy (AUP) is a policy that is regarding the usage of internet services and other network facilities with certain responsibility , rights and regulations.
  • This policy governs the internet use being done till permitted extent and is not interrupting security and ethics for any reason in corporate world, school premises etc.
  • Other options are incorrect because privacy policy is made for maintaining privacy.Fair use policy permits limited amount of copyrighted components to be used. Digital rights is related with regulation of digital element and environment.
  • Thus, the correct option is option(a).

7 0
1 year ago
1.Which of the following class definitions defines a legal abstract class?a. class A { abstract void unfinished() { } }b. class
xxMikexx [17]

Answer:(c) abstract class A { abstract void unfinished(); }

Explanation:

A legal abstract class must have the keyword abstract before the class and an abstract class has abstract functions with the keyword abstract written and a void as the return type.

8 0
2 years ago
Write a for loop that iterates from 1 to numbersamples to double any element's value in datasamples that is less than minvalue.
CaHeK987 [17]

Answer:

function dataSamples=AdjustMinValue(numberSamples, userSamples, minValue)

dataSamples=userSamples;

%for loop

for i=1:numberSamples

%checking if dataSamples value at index,i

%is less than minValue

if dataSamples(i)<minValue

%set double of dataSamples value

dataSamples(i)= 2*dataSamples(i);

end

end

end

Explanation:

The given code is in MATLAB.

4 0
1 year ago
Other questions:
  • ________ is used to undo unwanted database changes.
    15·2 answers
  • Which presenter would most likely benefit from a custom slide show?
    10·2 answers
  • When using preventative insecticides which holiday period should trigger an application?
    15·2 answers
  • Which one of the following is the best example of an authorization control? (a)- Biometric device (b)- Digital certificate (c)-A
    11·1 answer
  • Assume that getPlayer2Move works as specified, regardless of what you wrote in part (a) . You must use getPlayer1Move and getPla
    14·1 answer
  • In Section 8.5.4, we described a situation in which we prevent deadlock by ensuring that all locks are acquired in a certain ord
    11·1 answer
  • You are working on a documentation file userNotes.txt with some members of your software development team. Just before the file
    12·1 answer
  • Put the steps in order to produce the output shown below. Assume the indenting will be correct in the program.
    6·1 answer
  • Identify the tips to create a well-designed digital portfolio.
    10·1 answer
  • In a particular field, there are trees in a l single row from left to right. Each tree has a value V You cut trees from left to
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!