Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program will take the classic tongue-twister Peter Piper picked a peck of pickled peppers. and generate a tongue twister phrase based on user input

This program will take the classic tongue-twister "Peter Piper picked a peck of pickled peppers." and generate a tongue twister phrase based on user input for a last name, a unit of measurement and a vegetable. For all three cases, the user input may be multiple words.

Once read, the user input will be modified to fit the following rules:

  1. last name: No leading or trailing whitespace; the first character will be upper case and the rest lower case.
  2. unit of measurement and vegetable: No leading or trailing whitespace; all the characters in lower case.

Consider the following example with interleaved input (Zhang meter pumpkin , where ' ' is a new line) and output:

 

Note that in this program, unlike the previous ones, the prompts are not followed by a newline. That is, the input is:

 

and the output is:

 

Suggestion: Methods in the Scanner class (next() and nextLine()), String class (trim(), substring(), toUpperCase(), charAt(), etc.) and Character class may be helpful for this program. For more information on using Scanner, see theCS 200 Scanner Tutorial.

As the problems get more complicated, it is good to divide them up into smaller, easier to handle parts. Let's break this problem down into two parts: (1) a method for formatting the last name and (2) input and output in the main method.

(1) a) Copy the following method into your SillyString class.

 

b) Before implementing theproperCasemethod, think about examples of values (test cases) that might be passed in toname. Copy the following method into your SillyString class and replace the/*FIX ME*/with 3 different calls to the properCase method. Each call should test a different example input to the method. You should have a minimum of 3 tests, but you may have more.

 

c) Implement theproperCasemethod and use thetestProperCasemethod to test it before submitting.

(2) Complete the main method so that the output is produced and the input is read as described a

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

Students also viewed these Programming questions

Question

Can you help me with number 1? 5215

Answered: 1 week ago