Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

image text in transcribed

image text in transcribed

// 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 ) {

}

}

image text in transcribed

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 String

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

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago

Question

3. List ways to manage relationship dynamics

Answered: 1 week ago