Needs To be in JAVA everything is provided. Follow both steps and do the notes t
ID: 3698804 • Letter: N
Question
Needs To be in JAVA everything is provided. Follow both steps and do the notes too.
Alt Fn Ctri Part A: Ask the user to keep entering words as long as the user does not write "stop". Record the user input as a string or array element (your choice) by appending them to the current variable. (Hint: use +operator for appending to strings) Note: Make sure to include the user-entered "exit" in your analysis for Part B Note: Using Arrays will get you 10 points of extra credit if done correctly Part B: Once the user enters "exit", then the program should display the following menu: A. Display the total number of words entered by the user B. Display all the words entered by the user C. Display the total number of times the letter ”e" occurs D. Display the total number of words with more the one e" occurrence E. Display all the words in lowercase F. Display all words in uppercase G. Display if a certain word was entered by the user H. Exit Print a goodbye statement for the user to indicate the end of the program. Option Details: Option A; Displays the total number of words entered. Option B: Displays all the words the user entered. Option C: Displays the total number of times the letter e" occurs in all of the words entered Option D: Displays the total number of words with more the one "e" occurrence Option E: Displays all the words in lowercase. Option F: Displays all the words in uppercase. Option G: Asks the user to enter a word and then display if it the word was entered previously or not. Option H: Exits the Program The program should only exit when the user chooses to exit using this option. Note: Remember to include input validation! If the user, enters an option that is not valid (A-H) it should be handled accordingly.Explanation / Answer
MenuNoOfWords.java
import java.util.Scanner;
public class MenuNoOfWords {
public static void main(String[] args) {
// Declaring variables
int choice;
String word, str = "", arr[] = null;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Gettin the words entered by the user until the user enters "stop"
System.out.println("Enter words ("stop"):");
word = sc.next();
while (!word.equalsIgnoreCase("stop")) {
str += word + " ";
word = sc.next();
}
/* This while loop continues to execute
* until the user chooses valid choice or enters 'H'
*/
while (true) {
//displaying the menu
System.out.println(" A.Displays the total number of words entered");
System.out.println("B.Displays all the words the user entered");
System.out.println("C.Displays the total number of times the letter 'e' occurs in all of the words entered.");
System.out.println("D.Displays the total no of words with more than one 'e' occurrence");
System.out.println("E.Displays all the words in lowercase");
System.out.println("F.Displays all the words in uppercase");
System.out.println("G.Ask the user to enter a word and then display if it the word was entered previously or not");
System.out.println("H.Exits the progarm");
//getting the choice entered by the user
System.out.print(" Enter Choice :");
choice = sc.next(".").charAt(0);
//Based on the user choice the corresponding case will be executed
switch (choice) {
case 'A':
case 'a':
{
arr = str.split(" ");
System.out.println("Total No of words entered :" + arr.length);
continue;
}
case 'B':
case 'b':
{
arr = str.split(" ");
System.out.println("The Words entered by the user are :");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
continue;
}
case 'C':
case 'c':
{
arr = str.split(" ");
int countE = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length(); j++) {
if (arr[i].charAt(j) == 'e')
countE++;
}
}
System.out.println("Total number of times the letter 'e' occurs in all of the words entered :" + countE);
continue;
}
case 'D':
case 'd':
{
arr = str.split(" ");
int countDoubleEE = 0,
countE;
for (int i = 0; i < arr.length; i++) {
countE = 0;
for (int j = 0; j < arr[i].length(); j++) {
if (arr[i].charAt(j) == 'e') {
countE++;
}
}
if (countE >= 2) {
countDoubleEE++;
}
}
System.out.println("The total no of words with more than one 'e' occurrence:" + countDoubleEE);
continue;
}
case 'E':
case 'e':
{
arr = str.split(" ");
System.out.println("Displaying all the words in lowercase :");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i].toLowerCase());
}
continue;
}
case 'F':
case 'f':
{
arr = str.split(" ");
System.out.println("Displaying all the words in uppercase :");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i].toUpperCase());
}
continue;
}
case 'G':
case 'g':
{
int flag = 0;
arr = str.split(" ");
String searchWord;
System.out.print("Enter the word to search :");
searchWord = sc.next();
for (int i = 0; i < arr.length; i++) {
if (searchWord.equalsIgnoreCase(arr[i]))
flag = 1;
}
if (flag == 1) {
System.out.println("The word '" + searchWord + "' found");
} else {
System.out.println("The word '" + searchWord + "' not found");
}
continue;
}
case 'H':
case 'h':
{
break;
}
default:
{
System.out.println("** Invalid Choice **");
continue;
}
}
break;
}
}
}
____________________
Output:
Enter words ("stop"):
breeze
beautiful
hungry
magic
river
water
sunrise
brave
sqeeze
stop
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :A
Total No of words entered :9
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :B
The Words entered by the user are :
breeze
beautiful
hungry
magic
river
water
sunrise
brave
sqeeze
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :C
Total number of times the letter 'e' occurs in all of the words entered :11
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :D
The total no of words with more than one 'e' occurrence:2
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :E
Displaying all the words in lowercase :
breeze
beautiful
hungry
magic
river
water
sunrise
brave
sqeeze
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :F
Displaying all the words in uppercase :
BREEZE
BEAUTIFUL
HUNGRY
MAGIC
RIVER
WATER
SUNRISE
BRAVE
SQEEZE
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :G
Enter the word to search :brave
The word 'brave' found
A.Displays the total number of words entered
B.Displays all the words the user entered
C.Displays the total number of times the letter 'e' occurs in all of the words entered.
D.Displays the total no of words with more than one 'e' occurrence
E.Displays all the words in lowercase
F.Displays all the words in uppercase
G.Ask the user to enter a word and then display if it the word was entered previously or not
H.Exits the progarm
Enter Choice :H
______________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.