Java Provided code: // This is a \'helper\' class for Lab09. public class String
ID: 3733957 • Letter: J
Question
Java
Provided code:
// 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 )
{
}
}
----------------------------------------------------------------------------
// 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();
}
}
}
Explanation / Answer
public class StringPlay { // Static method to count the words in the input String public static int countWords( String phrase ) { int count = 1; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.