This problem is also one single problem, if you feel this is too long, if you ca
ID: 3808519 • Letter: T
Question
This problem is also one single problem, if you feel this is too long, if you can send me the codes from 4-7 please. 6.16 Program: Authoring assistant (Java) A 6.15 Warm up. Text analyzer & modifier (Java) Prompt the user to enter a string of their choosing. Store the text a string output the string (1 pt) in Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crewn and, yes, more volunteers more civilians more teacher in apace Nothing ends here: our hopes and our journeys continue You entered: We'll continue quest in space. There wil be more ahuttle flights and more ahuttle crews our and, yes, more volunteers, more civilians more teachers in space. Nothing enda here; our hopea and our journeys continue Implement a print method, outputs amenuo user options option. Each option is re by a single character presented editing the string, and returns the users entered menu If an invalid character is entered, continue to prompt for a valid choice. Hint Implement Quit before implementing other optons Cal printMenu0 in the main0 method. Continue to call printMenu0 until the user enters q to Quit (3 pts) MENU e Number of non-white apace character w Number of words
Explanation / Answer
This class having implemented all nethod:
package com.string;
public class TestString {
//Answer(4) :
public int getNumOfWords(String Sentence){
String[] splited =Sentence.split(" +");
return splited.length;
}
//Answer(5) :
public int findText(String find,String Sentence){
String[] splited =Sentence.split(" " );
int count=0 ;
for (int i = 0; i < splited.length; i++) {
String s= splited[i];
if(find.equals(splited[i])){
count++;
}
}
return count;
}
//Answer(6) :
public String replaceExlamation(String Sentence){
String edited=Sentence.replace("!", ".");
return edited;
}
//Answer(7) :
public String shortenSpaces(String Sentence){
String edited=Sentence.replaceAll(" ", " ");
return edited;
}
}
This is Driver class:
package com.string;
public class Driver {
public static void main(String[] args) {
// TODO Auto-generated method stub
String Sentence="We'll continue our quest in space. There will be more shuttel flight and more shuttel crews and yes, more volunteers, more civilians, more teacher in space. Nothing ends here; our hope and our journeys countinues! ";
TestString mw=new TestString();
System.out.println("Number of words in sentence:: "+mw.getNumOfWords(Sentence));
String find="more";
System.out.println(find+" words founds in sentence:: "+mw.findText(find, Sentence));
System.out.println("After replacing '!' by '.' Edited Text:: "+mw.replaceExlamation(Sentence));
System.out.println("After replacing double space by single space Edited Text:: "+mw.shortenSpaces(Sentence));
}
}
Output:
Number of words in sentence:: 35
more words founds in sentence:: 5
After replacing '!' by '.' Edited Text:: We'll continue our quest in space. There will be more shuttel flight and more shuttel crews and yes, more volunteers, more civilians, more teacher in space. Nothing ends here; our hope and our journeys countinues.
After replacing double space by single space Edited Text:: We'll continue our quest in space. There will be more shuttel flight and more shuttel crews and yes, more volunteers, more civilians, more teacher in space. Nothing ends here; our hope and our journeys countinues!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.