Assignment 8
Due Tuesday, May 8 at 1:20pm on Canvas

Assignment 8.1: 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. 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()
    3. Compare the two words using compareTo to determine which one comes first alphabetically.
  2. Example Run: 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
    For example: Hello World!<Enter>: Hello World!
    You entered: first = "Hello" and second = "World!"
    Parenthesis below show correct results for example words.
    *** Measuring word length ***
    First word length (5): 5
    Second word length (6): 6
    Longer word (World!): World!
    *** Merging Strings ***
    Extracted (Held!): Held!
    *** Comparing the two words ***
    Hello comes before World!

    In the above example run, 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. The values in (parentheses) are expected values when entering the example input.

  3. After displaying the output, exit the program.

Assignment 8.2: Student ID Numbers (10 pts)

  • Open a new Java project in Eclipse called StudentID with a class named
  • Your program should prompt a user to enter a student ID number as a series of numbers.
  • It will check whether the user entered a valid 8-digit de Anza student ID number and report an error message if the ID number entered is too short or too long (no other error checking is required).
  • It will then display the ID number in the format XXX-XXX-XX
  • Your program should work identically to these examples (except user input will vary):

Please enter your 8 digit student ID number: 203456
Sorry! That ID is invalid.
Please run the program again.
  • Alternately:

Please enter your 8 digit student ID number: 1034566330
Sorry! That ID is invalid.
Please run the program again.

  • Alternately,
Please enter your 8 digit student ID number: 20456855
You entered: 204-568-55
  • Hint: Use Strings, not ints. And, make use of the String methods we discussed in class under Lesson 7.
  • Important: You are required to use exactly one if and one else for full credit. Do not use else if for this assignment!
  • Submit to Canvas when you are finished.