Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java eclipse To Do: QUOTE AND QUOTEDRIVER. NOTE: There is a start file for this. Write a class named Quote with a single instance variable

java eclipse

To Do: QUOTE AND QUOTEDRIVER. NOTE: There is a start file for this.

Write a class named Quote with a single instance variable named quote that is a String. Write the no-argument and full constructor and the getter and setter. The class should also have methods returns the following:

The number of characters in the quote

The quote in all uppercase letters

The quote in all lowercase letters

The first character in the quote

the number of vowels in the string

the number of consonants in the string.

A method that asks the user to enter a character. The program should count and return the number of times that the specified character appears in the string.

Demonstrate the class in a program named QuoteDriver that performs the following:

The user is asked to enter a string.

The program displays a menu giving the user a choice of the methods above. The user should also have a choice of either entering another String or of exiting.

The program performs the operation selected by the user and repeats until the user selects to exit the program.

public class Quote {

public int numChars(){

// you code this

return 0;

}

//b. The quote in all uppercase letters

public String upper() {

//you code this

return "";

}

//The quote in all lowercase letters

public String lower() {

//you code this

return "";

}

//d. The first character in the quote

public char firstChar(){

// you code this

return ' ';

}

//e. the number of vowels in the string

public int numVowels() {

//you code this

return 0;

}

//f. the number of consonants in the string.

public int numCons() {

// you code this

return 0;

}

//g. A method that asks the user to enter a character.

//The program should count and return the number of times that the specified character appears in the string.

public int numTimes(char what){

// you code this

return 0;

}

}

QUOTEDRIVER

import java.util.Scanner;

/* Demonstrate the class in a program named QuoteDriver that performs the following:

a) The user is asked to enter a string.

b) The program displays a menu giving the user a choice of the methods above.

The user should also have a choice of either entering another String or of exiting.

c) The program performs the operation selected by the user and repeats

until the user selects to exit the program.

*/

public class QuoteDriver {

public static void main(String[] args) {

// ask the user for a quote. Store it in a String named quote.

// Create an instance of the Quote class calling the full constructor. Name the instance myQuote.

int choice = 0;

while (choice != 999) {

choice = menu();

if (choice ==999) {

System.out.println("Thanks for playing my game!");

System.exit(0);

}

else if (choice ==8){

System.out.println("Give me a new quote to analyze");

// ask for a new quote. Store it in a String named quote.

// use the setter to update the value of the field in the myQuote instance

}

else if (choice==1) {

System.out.println("The number of characters in the quote is "+ myQuote.numChars() );

}

else if (choice==2) {

System.out.println("The quote in all upper case is "+ myQuote.upper() );

}

else if (choice==3) {

System.out.println("The quote in all lower case is "+ myQuote.lower() );

}

else if (choice==4) {

System.out.println("The first character of the quote is "+ myQuote.firstChar() );

}

else if (choice==5) {

System.out.println("The number of vowels in the quote is "+ myQuote.numVowels() );

}

else if (choice==6) {

System.out.println("The number of consanants in the quote is "+ myQuote.numCons() );

}

else if (choice==7) {

System.out.println("What character are you looking for?");

String stWhich = scan.nextLine();

char which = stWhich.charAt(0);

System.out.println("The number of times the character '" + which + "' occurs in the quote is "+ myQuote.numTimes(which) );

}

}

}

public static int menu() {

Scanner scan = new Scanner(System.in);

System.out.println(" Which of the following would you like:");

System.out.println("1. The number of characters in the quote");

System.out.println("2. The quote in all uppercase letters");

System.out.println("3. The quote in all lowercase letters");

System.out.println("4. The first character in the quote");

System.out.println("5. The number of vowels in the string");

System.out.println("6. The number of consonants in the string");

System.out

.println("7. To count the number of occurrences of a specific character in the string");

System.out.println("8. Enter an new string");

System.out.println("999. Quit the program");

System.out.println("CHOICE:");

int choice = scan.nextInt();

return choice;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions