Question
Java only please ***********************PROVIDED CODE*********************************** // This is a test harness for Lab09. import java.util.Scanner; public class Lab09 { public static void main( String[] args)
Java only please
***********************PROVIDED CODE***********************************
// This is a test harness for Lab09.
import java.util.Scanner;
public class Lab09 { public static void main( String[] args) { Scanner input = new Scanner( System.in ); String finish = "Finish"; System.out.printf("%nEnter a phrase containing at least three words%nOr enter finish to stop" ); String newPhrase = input.nextLine(); // You need to change the control condition here while( newPhrase != finish ) { // Call static methods of class StringPlay System.out.printf("Your phrase contains %d words.", StringPlay.countWords( newPhrase ) ); System.out.printf("%nYour phrase with all letters in uppercase: %s", StringPlay.changeToUppercase( newPhrase ) ); System.out.printf("%nThe middle word of your phrase is: %S%n%n", StringPlay.findMiddleWord( newPhrase ) ); System.out.printf("%nEnter a phrase containing at least three words%nOr enter finish to stop" ); newPhrase = input.nextLine(); } } }
***************************************************************
// This is a 'helper' class for Lab09.
public class StringPlay { // Static method to count the words in the input String public static int countWords( String phrase ) {
} // Static method to change all letters in the input String to uppercase public static StringBuilder changeToUppercase( String phrase ) {
} //Static method to find middle word of the input String public static String findMiddleWord( String phrase ) {
}
}
****************************END******************************
Thanks!
Purpose: Working with strings General Information You will write three static methods to manipulate an input String in different ways using various String methods. You need to provide the code for each of the three static methods in class StringPlay (requirements for each listed below) You will also change the control statement in the test harness to allow for variations in the sentinel value. You need to modify the loop control condition in Lab09.java so that user inputs of finish "FINISH", "FiniSH", "fINISH", etc. will end the loop. Provided Resources 1. 2. 3. 4. Lab 09 Instructions, including requirements A test harness for your code (Lab09.java) A framework for StringPlay.java (three static methods need to be added) Sample output Requirements a) Add the necessary code to StringPlay.java Method countWords 1. Receives a String value containing the user-input phrase passed from Lab09.java 2. Separates the phrase into individual words 3. Returns an int value containing a count of the individual words in the phrase Method changeToUppercase 1. Receives a String value containing the user-input phrase passed from Lab09.java 2. Declares a StringBuilder object 3. Separated the phrase into individual words, storing those words in an array of String type 4. Beginning with the first entry in the array, appends each word with all letters changed to uppercase (and a following space) to the StringBuilder object 5. Returns the StringBuilder object Method findMiddleWord 1. Receives a String value containing the user-input phrase passed from Lab09.java 2. Determines the number of words in the String 3. Finds the 'middle' word 4. Returns the String representing the middle or center word in the StringStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started