Assignment 7

Due Friday, May 8 at 11:59pm on Canvas

Important: To receive credit, you must only use concepts and methods taught in class to complete this assignment - or you will receive a 0 on this assignment.

Pair Programming Required (Or You Will Receive a 0)
  • Both partners fill in, sign, date, and submit the pair programming contract
  • Upload the document(s) along with your Lab code to Canvas.
  • Please make sure both your names are on your file (hint: use a comment).
  • If you need help finding a partner, please contact me as soon as possible.

Assignment 7: String Manipulation (10 pts)

  1. Complete each of the following String manipulation problems in a file called Your program should read in two Strings from the keyboard as shown below. It should then do the following:
    1. Measure the length of both words entered by the user and save the length in the related variable. Then use an if-statement to compare the two word lengths and print the word that is longer.
    2. Determine whether the two words are the same (Hint: remember the equals method?)
    3. Concatenate the first 2 letters of the variable first and the last 3 letters of variable second. Assign the result of the concatenation operations to variable extract. Hint: Use charAt()
      1. Note that you may assume the user enters words of sufficient length to complete this step
    4. Compare the two words using compareTo to determine which one comes first alphabetically.
  2. Sample Output: The input prompts and outputs of the program must look like the following for full credit, including the same order of input and exact wording of the output. For the input shown you must get the same output. However, the output must change properly if the inputs are different.
    *** String Manipulation ***
    Enter two words separated by a space, and press the Enter key
    Enter your input: Hello World!
    You entered: first = "Hello" and second = "World!"
    First word length: 5
    Second word length: 6
    Longer word: World!
    Words are the same: false
    Merged words: Held!
    Word order: Hello comes before World!

    In the sample output, the user entered the words shown in italics (for emphasis) to produce the output. Your program does NOT print the characters in italics, nor does the user input appear in italics. 

*** String Manipulation ***
Enter two words separated by a space, and press the Enter key
Enter your input: Bye Bye

You entered: first = "Bye" and second = "Bye"

First word length: 3
Second word length: 3
Longer word: Bye

Words are the same: true

Merged words: ByBye

Word order: Bye comes before Bye
After displaying the output, exit the program. Submit your file to Canvas once it is complete.