Assignment 8
Due Tuesday, October 23 at 9:20am on Canvas

Assignment 8.1: Jokes (10 pts)

Image of Mae West
Write a program to ask a user whether (s)he wants to hear a bad joke.
If the user indicates no, the program should quote Mae West, a classic Hollywood actress, who was famous for her amusing one-liners.

“Between two evils, I always pick the one I never tried before.”

-Mae West

If the user indicates yes, the program should print out the computer joke:


"Q: Why did the computer get cold?
A: Because it forgot to close Windows."


Your program should work identically to the example output below.

Note that your output should display the "" around the jokes.

Note that you are required to use exactly one if statement and one else statement to receive full credit on this assignment. (No else if needed!)

Submit Joke.java to Canvas when you are finished.

Example Output:


Want to hear a bad joke (yes/no)? no
Okay. I will tell you a good one:

Between two evils, I always pick the one I never tried before.
- Mae West

Alternately,

Want to hear a bad joke (yes/no)? yes

"Q: Why did the computer get cold?
A: Because it forgot to close Windows."


Assignment 8.2: String Manipulation (10 pts)
  1. Complete each of the following String manipulation problems in a file called Str.java. 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.3: Days in a Month (10 pts)
  • Develop a program that first asks the user to enter a month (January, February, and so on) and then prints the number of days in the month followed by the word "days". For February, print the phrase "28 or 29 days".
  • The user should be able to enter upper or lower case letters for the days of the month and the program should still recognize the entry month.
  • Submit MonthDays.java when finished your output is identical to what is shown below.
Sample Output:

I will print the number of days in a month.
Enter the month (January - December): September
30 days

Alternately:

I will print the number of days in a month.
Enter the month
(January - December): february
28 or 29 days


Alternately:

I will print the number of days in a month.
Enter the month
(January - December): JaNuAry
31 days

Hint: Thirty days hath September