SlideShare a Scribd company logo
1 of 14
Download to read offline
import java.util.Scanner;
public class AuthoringAssistant {
// Creates an instance of Scanner class object
private static Scanner scanner = new Scanner(System.in);
/**
*
* The method that replaces two or more sapces with single spaces
* */
private static String shortenSpace(String text) {
String temp = text.trim().replaceAll(" +", " ");
return temp;
}
/**
* The method replaces all exclamation marks with character '.'
* */
private static String replaceExclamation(String text) {
String temp = text.replaceAll("!", ".");
return temp;
}
/**
* The method findText that finds the number of occurenence of find in text
* and returns the count
* */
private static int findText(String text, String find) {
int count = 0;
int i = 0;
while ((i = text.indexOf(find)) != -1) {
text = text.substring(i + find.length());
count += 1;
}
return count;
}
/**
* the method takes a string and returns the number of words in the text.
* */
private static int getNumOfWords(String text) {
// call split method that returns the array of words
// split by spaces
text = shortenSpace(text);
String[] words = text.split(" ");
// return count of words
return words.length;
}
/*
* The method getNumOfNonWSCharacters that remmoves the whitepsaces and
* returns the lenght of the text
*/
private static int getNumOfNonWSCharacters(String text) {
text = text.trim().replaceAll("s", "");
return text.length();
}
/**
* The method printMenu that prints a menu of choices and prompts user to
* enter choice.
* */
private static void printMenu() {
System.out.println(" MENU");
System.out.println("c - Number of non-whitespace characters");
System.out.println("w - Number of words");
System.out.println("f - Find text");
System.out.println("r - Replace all !'s");
System.out.println("s - Shorten spaces");
System.out.println("q - Quit");
System.out.println(" Choose an option: ");
}
public static void main(String[] args) {
while(true) {
//prompt for the text
System.out.println("Enter a sample text: ");
String text = scanner.nextLine();
//Display user input
System.out.println("You entered: " + text);
//Display menu
printMenu();
char ch = scanner.nextLine().charAt(0);
switch (ch) {
case 'q':
// close the program
// System.out.println("Exit the program");
System.exit(0);
case 'c': // Number of non-whitespace characters
int cntNonWhitespaces = getNumOfNonWSCharacters(text);
System.out.println("Number of non-whitespace characters: " + cntNonWhitespaces);
break;
case 'w': // Number of words
int wordsCount = getNumOfWords(text);
System.out.println("Number of words: " + wordsCount);
break;
case 'f': // Find text
System.out.println("Enter a word or phrase to be found: ");
String find = scanner.nextLine();
int findCount = findText(text, find);
System.out.println(""" + find + "" instances: " + findCount);
break;
case 'r': // Replace all !'s
String newstring = replaceExclamation(text);
System.out.println("Edited text: " + newstring);
break;
case 's': // Shorten spaces
newstring = shortenSpace(text);
System.out.println("Edited text:" + newstring);
break;
default:
System.out.println("Invalid option. Please try again");
}
System.out.println();
}
}
}
SAMPLE OUTPUT:
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
c
Number of non-whitespace characters: 134
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
w
Number of words: 26
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
f
Enter a word or phrase to be found:
more
"more" instances: 5
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
f
Enter a word or phrase to be found:
more shuttle
"more shuttle" instances: 2
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
r
Edited text: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our! quest in space. There will be more shuttle flights and !more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our! quest in space. There will be more shuttle flights
and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
r
Edited text: We'll continue our. quest in space. There will be more shuttle flights
and .more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
s
Edited text:We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
q
Solution
import java.util.Scanner;
public class AuthoringAssistant {
// Creates an instance of Scanner class object
private static Scanner scanner = new Scanner(System.in);
/**
*
* The method that replaces two or more sapces with single spaces
* */
private static String shortenSpace(String text) {
String temp = text.trim().replaceAll(" +", " ");
return temp;
}
/**
* The method replaces all exclamation marks with character '.'
* */
private static String replaceExclamation(String text) {
String temp = text.replaceAll("!", ".");
return temp;
}
/**
* The method findText that finds the number of occurenence of find in text
* and returns the count
* */
private static int findText(String text, String find) {
int count = 0;
int i = 0;
while ((i = text.indexOf(find)) != -1) {
text = text.substring(i + find.length());
count += 1;
}
return count;
}
/**
* the method takes a string and returns the number of words in the text.
* */
private static int getNumOfWords(String text) {
// call split method that returns the array of words
// split by spaces
text = shortenSpace(text);
String[] words = text.split(" ");
// return count of words
return words.length;
}
/*
* The method getNumOfNonWSCharacters that remmoves the whitepsaces and
* returns the lenght of the text
*/
private static int getNumOfNonWSCharacters(String text) {
text = text.trim().replaceAll("s", "");
return text.length();
}
/**
* The method printMenu that prints a menu of choices and prompts user to
* enter choice.
* */
private static void printMenu() {
System.out.println(" MENU");
System.out.println("c - Number of non-whitespace characters");
System.out.println("w - Number of words");
System.out.println("f - Find text");
System.out.println("r - Replace all !'s");
System.out.println("s - Shorten spaces");
System.out.println("q - Quit");
System.out.println(" Choose an option: ");
}
public static void main(String[] args) {
while(true) {
//prompt for the text
System.out.println("Enter a sample text: ");
String text = scanner.nextLine();
//Display user input
System.out.println("You entered: " + text);
//Display menu
printMenu();
char ch = scanner.nextLine().charAt(0);
switch (ch) {
case 'q':
// close the program
// System.out.println("Exit the program");
System.exit(0);
case 'c': // Number of non-whitespace characters
int cntNonWhitespaces = getNumOfNonWSCharacters(text);
System.out.println("Number of non-whitespace characters: " + cntNonWhitespaces);
break;
case 'w': // Number of words
int wordsCount = getNumOfWords(text);
System.out.println("Number of words: " + wordsCount);
break;
case 'f': // Find text
System.out.println("Enter a word or phrase to be found: ");
String find = scanner.nextLine();
int findCount = findText(text, find);
System.out.println(""" + find + "" instances: " + findCount);
break;
case 'r': // Replace all !'s
String newstring = replaceExclamation(text);
System.out.println("Edited text: " + newstring);
break;
case 's': // Shorten spaces
newstring = shortenSpace(text);
System.out.println("Edited text:" + newstring);
break;
default:
System.out.println("Invalid option. Please try again");
}
System.out.println();
}
}
}
SAMPLE OUTPUT:
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
c
Number of non-whitespace characters: 134
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
w
Number of words: 26
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
f
Enter a word or phrase to be found:
more
"more" instances: 5
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
f
Enter a word or phrase to be found:
more shuttle
"more shuttle" instances: 2
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
r
Edited text: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our! quest in space. There will be more shuttle flights and !more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our! quest in space. There will be more shuttle flights
and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
r
Edited text: We'll continue our. quest in space. There will be more shuttle flights
and .more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
s
Edited text:We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
Enter a sample text:
We'll continue our quest in space. There will be more shuttle flights and more
shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
You entered: We'll continue our quest in space. There will be more shuttle flights
and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
MENU
c - Number of non-whitespace characters
w - Number of words
f - Find text
r - Replace all !'s
s - Shorten spaces
q - Quit
Choose an option:
q

More Related Content

Similar to import java.util.Scanner;public class AuthoringAssistant {    .pdf

PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and PatternsHenry Osborne
 
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdfDOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdfarchanaemporium
 
Write a class of static methods that accomplish the following tasks. .docx
 Write a class of static methods that accomplish the following tasks. .docx Write a class of static methods that accomplish the following tasks. .docx
Write a class of static methods that accomplish the following tasks. .docxajoy21
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdfarkurkuri
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.Icalia Labs
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
 

Similar to import java.util.Scanner;public class AuthoringAssistant {    .pdf (20)

StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
 
PHP Strings and Patterns
PHP Strings and PatternsPHP Strings and Patterns
PHP Strings and Patterns
 
Intro toswift1
Intro toswift1Intro toswift1
Intro toswift1
 
Team 1
Team 1Team 1
Team 1
 
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdfDOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
 
Strings in java
Strings in javaStrings in java
Strings in java
 
C q 3
C q 3C q 3
C q 3
 
Computer programming 2 Lesson 11
Computer programming 2  Lesson 11Computer programming 2  Lesson 11
Computer programming 2 Lesson 11
 
Write a class of static methods that accomplish the following tasks. .docx
 Write a class of static methods that accomplish the following tasks. .docx Write a class of static methods that accomplish the following tasks. .docx
Write a class of static methods that accomplish the following tasks. .docx
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdf
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
 
Python Strings.pptx
Python Strings.pptxPython Strings.pptx
Python Strings.pptx
 
Strings
StringsStrings
Strings
 
Array &strings
Array &stringsArray &strings
Array &strings
 
11-ch04-3-strings.pdf
11-ch04-3-strings.pdf11-ch04-3-strings.pdf
11-ch04-3-strings.pdf
 
c programming
c programmingc programming
c programming
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 

More from noelbuddy

1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdfnoelbuddy
 
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdfnoelbuddy
 
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdfnoelbuddy
 
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdfnoelbuddy
 
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdfnoelbuddy
 
just hit the ln button sorry guys .pdf
                     just hit the ln button sorry guys                .pdf                     just hit the ln button sorry guys                .pdf
just hit the ln button sorry guys .pdfnoelbuddy
 
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf
I have seen in a table that pKa of H3PO4 =2.12 s.pdfnoelbuddy
 
#includeiostream#includestring#include fstreamusing name.pdf
#includeiostream#includestring#include fstreamusing name.pdf#includeiostream#includestring#include fstreamusing name.pdf
#includeiostream#includestring#include fstreamusing name.pdfnoelbuddy
 
Yes. You can prove it experimentally, but if you.pdf
                     Yes.  You can prove it experimentally, but if you.pdf                     Yes.  You can prove it experimentally, but if you.pdf
Yes. You can prove it experimentally, but if you.pdfnoelbuddy
 
the one which is oxidized is reducing agent Pb wa.pdf
                     the one which is oxidized is reducing agent Pb wa.pdf                     the one which is oxidized is reducing agent Pb wa.pdf
the one which is oxidized is reducing agent Pb wa.pdfnoelbuddy
 
   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdfnoelbuddy
 
What inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfWhat inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfnoelbuddy
 
The tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfThe tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfnoelbuddy
 
public class Party {    private int guests;      return .pdf
public class Party {    private int guests;        return .pdfpublic class Party {    private int guests;        return .pdf
public class Party {    private int guests;      return .pdfnoelbuddy
 
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfThe main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfnoelbuddy
 
The motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfThe motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfnoelbuddy
 
The formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfThe formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfnoelbuddy
 
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf
Density = MassVolume = 4.023.57 = 1.126 gml .pdfnoelbuddy
 
D is correct. Solution D .pdf
                     D is correct. Solution                     D .pdf                     D is correct. Solution                     D .pdf
D is correct. Solution D .pdfnoelbuddy
 
doesnt work since S in SO3 is +6 oxidation stat.pdf
                     doesnt work since S in SO3 is +6 oxidation stat.pdf                     doesnt work since S in SO3 is +6 oxidation stat.pdf
doesnt work since S in SO3 is +6 oxidation stat.pdfnoelbuddy
 

More from noelbuddy (20)

1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
1.The pozzolanic reaction is the chemical reaction that occurs in .pdf
 
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
11.B. Association of Southeast Asian NationsExplanationASEAN .pdf
 
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf1. Proteobacteria. It is the largest and metabolically diverse group.pdf
1. Proteobacteria. It is the largest and metabolically diverse group.pdf
 
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
1. Adapt (adaptation)2. Evolve (evolution)3. Individual4. Non .pdf
 
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
1) WW1 - Great war or world war 1 is begin on 28th july 1914 in Eur.pdf
 
just hit the ln button sorry guys .pdf
                     just hit the ln button sorry guys                .pdf                     just hit the ln button sorry guys                .pdf
just hit the ln button sorry guys .pdf
 
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf                     I have seen in a table that pKa of H3PO4 =2.12  s.pdf
I have seen in a table that pKa of H3PO4 =2.12 s.pdf
 
#includeiostream#includestring#include fstreamusing name.pdf
#includeiostream#includestring#include fstreamusing name.pdf#includeiostream#includestring#include fstreamusing name.pdf
#includeiostream#includestring#include fstreamusing name.pdf
 
Yes. You can prove it experimentally, but if you.pdf
                     Yes.  You can prove it experimentally, but if you.pdf                     Yes.  You can prove it experimentally, but if you.pdf
Yes. You can prove it experimentally, but if you.pdf
 
the one which is oxidized is reducing agent Pb wa.pdf
                     the one which is oxidized is reducing agent Pb wa.pdf                     the one which is oxidized is reducing agent Pb wa.pdf
the one which is oxidized is reducing agent Pb wa.pdf
 
   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf   Internet the information super highway, open access, public user.pdf
   Internet the information super highway, open access, public user.pdf
 
What inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdfWhat inequities exist in health careIf you take the question from.pdf
What inequities exist in health careIf you take the question from.pdf
 
The tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdfThe tops for collecting network based evidenceyou think that your.pdf
The tops for collecting network based evidenceyou think that your.pdf
 
public class Party {    private int guests;      return .pdf
public class Party {    private int guests;        return .pdfpublic class Party {    private int guests;        return .pdf
public class Party {    private int guests;      return .pdf
 
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdfThe main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
The main culprit of the scene is suspect 2 ; Roger Coleman, the DNA .pdf
 
The motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdfThe motor ANS is divided into the sympathetic nervous system, which .pdf
The motor ANS is divided into the sympathetic nervous system, which .pdf
 
The formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdfThe formation of a disaccharide involves the condensation of two mon.pdf
The formation of a disaccharide involves the condensation of two mon.pdf
 
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf                     Density = MassVolume = 4.023.57 = 1.126 gml   .pdf
Density = MassVolume = 4.023.57 = 1.126 gml .pdf
 
D is correct. Solution D .pdf
                     D is correct. Solution                     D .pdf                     D is correct. Solution                     D .pdf
D is correct. Solution D .pdf
 
doesnt work since S in SO3 is +6 oxidation stat.pdf
                     doesnt work since S in SO3 is +6 oxidation stat.pdf                     doesnt work since S in SO3 is +6 oxidation stat.pdf
doesnt work since S in SO3 is +6 oxidation stat.pdf
 

Recently uploaded

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 

Recently uploaded (20)

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 

import java.util.Scanner;public class AuthoringAssistant {    .pdf

  • 1. import java.util.Scanner; public class AuthoringAssistant { // Creates an instance of Scanner class object private static Scanner scanner = new Scanner(System.in); /** * * The method that replaces two or more sapces with single spaces * */ private static String shortenSpace(String text) { String temp = text.trim().replaceAll(" +", " "); return temp; } /** * The method replaces all exclamation marks with character '.' * */ private static String replaceExclamation(String text) { String temp = text.replaceAll("!", "."); return temp; } /** * The method findText that finds the number of occurenence of find in text * and returns the count * */ private static int findText(String text, String find) { int count = 0; int i = 0; while ((i = text.indexOf(find)) != -1) { text = text.substring(i + find.length()); count += 1; } return count; } /** * the method takes a string and returns the number of words in the text.
  • 2. * */ private static int getNumOfWords(String text) { // call split method that returns the array of words // split by spaces text = shortenSpace(text); String[] words = text.split(" "); // return count of words return words.length; } /* * The method getNumOfNonWSCharacters that remmoves the whitepsaces and * returns the lenght of the text */ private static int getNumOfNonWSCharacters(String text) { text = text.trim().replaceAll("s", ""); return text.length(); } /** * The method printMenu that prints a menu of choices and prompts user to * enter choice. * */ private static void printMenu() { System.out.println(" MENU"); System.out.println("c - Number of non-whitespace characters"); System.out.println("w - Number of words"); System.out.println("f - Find text"); System.out.println("r - Replace all !'s"); System.out.println("s - Shorten spaces"); System.out.println("q - Quit"); System.out.println(" Choose an option: "); } public static void main(String[] args) { while(true) { //prompt for the text System.out.println("Enter a sample text: "); String text = scanner.nextLine();
  • 3. //Display user input System.out.println("You entered: " + text); //Display menu printMenu(); char ch = scanner.nextLine().charAt(0); switch (ch) { case 'q': // close the program // System.out.println("Exit the program"); System.exit(0); case 'c': // Number of non-whitespace characters int cntNonWhitespaces = getNumOfNonWSCharacters(text); System.out.println("Number of non-whitespace characters: " + cntNonWhitespaces); break; case 'w': // Number of words int wordsCount = getNumOfWords(text); System.out.println("Number of words: " + wordsCount); break; case 'f': // Find text System.out.println("Enter a word or phrase to be found: "); String find = scanner.nextLine(); int findCount = findText(text, find); System.out.println(""" + find + "" instances: " + findCount); break; case 'r': // Replace all !'s String newstring = replaceExclamation(text); System.out.println("Edited text: " + newstring); break;
  • 4. case 's': // Shorten spaces newstring = shortenSpace(text); System.out.println("Edited text:" + newstring); break; default: System.out.println("Invalid option. Please try again"); } System.out.println(); } } } SAMPLE OUTPUT: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: c Number of non-whitespace characters: 134 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters
  • 5. w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: w Number of words: 26 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: f Enter a word or phrase to be found: more "more" instances: 5 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces
  • 6. q - Quit Choose an option: f Enter a word or phrase to be found: more shuttle "more shuttle" instances: 2 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: r Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Enter a sample text: We'll continue our! quest in space. There will be more shuttle flights and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our! quest in space. There will be more shuttle flights and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: r
  • 7. Edited text: We'll continue our. quest in space. There will be more shuttle flights and .more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: s Edited text:We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: q Solution import java.util.Scanner;
  • 8. public class AuthoringAssistant { // Creates an instance of Scanner class object private static Scanner scanner = new Scanner(System.in); /** * * The method that replaces two or more sapces with single spaces * */ private static String shortenSpace(String text) { String temp = text.trim().replaceAll(" +", " "); return temp; } /** * The method replaces all exclamation marks with character '.' * */ private static String replaceExclamation(String text) { String temp = text.replaceAll("!", "."); return temp; } /** * The method findText that finds the number of occurenence of find in text * and returns the count * */ private static int findText(String text, String find) { int count = 0; int i = 0; while ((i = text.indexOf(find)) != -1) { text = text.substring(i + find.length()); count += 1; } return count; } /** * the method takes a string and returns the number of words in the text. * */ private static int getNumOfWords(String text) {
  • 9. // call split method that returns the array of words // split by spaces text = shortenSpace(text); String[] words = text.split(" "); // return count of words return words.length; } /* * The method getNumOfNonWSCharacters that remmoves the whitepsaces and * returns the lenght of the text */ private static int getNumOfNonWSCharacters(String text) { text = text.trim().replaceAll("s", ""); return text.length(); } /** * The method printMenu that prints a menu of choices and prompts user to * enter choice. * */ private static void printMenu() { System.out.println(" MENU"); System.out.println("c - Number of non-whitespace characters"); System.out.println("w - Number of words"); System.out.println("f - Find text"); System.out.println("r - Replace all !'s"); System.out.println("s - Shorten spaces"); System.out.println("q - Quit"); System.out.println(" Choose an option: "); } public static void main(String[] args) { while(true) { //prompt for the text System.out.println("Enter a sample text: "); String text = scanner.nextLine(); //Display user input
  • 10. System.out.println("You entered: " + text); //Display menu printMenu(); char ch = scanner.nextLine().charAt(0); switch (ch) { case 'q': // close the program // System.out.println("Exit the program"); System.exit(0); case 'c': // Number of non-whitespace characters int cntNonWhitespaces = getNumOfNonWSCharacters(text); System.out.println("Number of non-whitespace characters: " + cntNonWhitespaces); break; case 'w': // Number of words int wordsCount = getNumOfWords(text); System.out.println("Number of words: " + wordsCount); break; case 'f': // Find text System.out.println("Enter a word or phrase to be found: "); String find = scanner.nextLine(); int findCount = findText(text, find); System.out.println(""" + find + "" instances: " + findCount); break; case 'r': // Replace all !'s String newstring = replaceExclamation(text); System.out.println("Edited text: " + newstring); break; case 's': // Shorten spaces newstring = shortenSpace(text);
  • 11. System.out.println("Edited text:" + newstring); break; default: System.out.println("Invalid option. Please try again"); } System.out.println(); } } } SAMPLE OUTPUT: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: c Number of non-whitespace characters: 134 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text
  • 12. r - Replace all !'s s - Shorten spaces q - Quit Choose an option: w Number of words: 26 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: f Enter a word or phrase to be found: more "more" instances: 5 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option:
  • 13. f Enter a word or phrase to be found: more shuttle "more shuttle" instances: 2 Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: r Edited text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Enter a sample text: We'll continue our! quest in space. There will be more shuttle flights and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our! quest in space. There will be more shuttle flights and !more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: r Edited text: We'll continue our. quest in space. There will be more shuttle flights and .more shuttle crews and, yes, more volunteers, more civilians, more teachers in space.
  • 14. Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: s Edited text:We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option: q