Assignment 8
Due Tuesday, February 12 at 11: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
    Enter your input: Hello World!
    
    You entered: first = "Hello" and second = "World!"
    
    *** Measuring word length ***
    First word length: 5
    Second word length: 6
    Longer word: World!
    
    *** Merging Strings ***
    Extracted: 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: Phone Chatbot (10 pts)

  • For this programming assignment, we write a basic chatbot program.
  • For fun, try having a conversation with an online chatbot here or here.
  • Some sources estimate that 25% of customer services will be handled by Chatbots in 2020, vs. 2% in 2017 (1).
  • The chatbot we are designing must ask you the following questions:
  1. What is your name?
  2. What is your phone number?
  3. What is your phone plan?
  4. How many GB of data this month?
  • Just don't give the chatbot your credit card number! 😉
Project Specifications
  • Write a chatbot program that interacts with the user as described in the Interaction section below to calculate a phone bill.
  • Name the source code file Phonebot.java and include all your code in this single file.
  • Be careful of the spelling, including capitalization, as you will lose points for a misspelled name. Naming is important in programming.
  • Interaction: Interact with the user with the following inputs in the order given (and no other input) as follows:
  • Name: open the conversation with a welcome and find out the user's name (String).
    • Reply with a greeting that displays the user's name, like "Thanks for calling RobuCast <user's name>!".
  • Phone: find out the user's phone number (String).
    • Reply with a statement like "Looking up phone number <phone number>...".
  • Plan: ask the user for their plan type entered as a basic, gold or unlimited
    • Reply by spelling out the full plan name, (basic package, gold members, unlimited plan)
  • Data: request user's data usage in Gigabytes (double).
    • Reply with a comment that restates the amount of data, such as "Wow, <amount> is a lot of data! You should upgrade."
  • Total: display the total bill and say goodbye to <user's name>.
  • The parenthesis show the required data types for the input. Make sure to restate the input where indicated by the word "reply" or angle brackets.
  • Assume the user enters only valid data.
  • The phone bill is based on the phone plan and the number of Gigabytes (GB) of data used per month. Here are the different plans:
    • Basic package: the $24.95 per month plan provides 2 GB of data. Additional data are $7.00 per Gigabyte.
    • Gold member plan: the $39.95 per month plan provides 5 GB of data. Additional data are $5.00 per Gigabyte.
    • Unlimited plan: the $59.95 per month plan provides unlimited data.
  • Hint: Assume that the user input will be one word responses at most. Use only input.next() statements in this program (no input.nextLine() statements).
  • Example Output: The following shows example outputs. Your program prompts and output does not have to exactly match mine.
  • Your program does need to reply to all input as stated in Interactions above, but you are free to give your chatbot a personality.
  • Make sure the inputs are in the correct order and that you restate the data entered by the user.
  • Otherwise, have fun with it!
  • When you are finished, upload your PhoneBot.java file to Canvas
Welcome to RobuCast.
What is your name? Jennifer
Thanks for calling RobuCast Jennifer!
What is your phone number? 555-2368
Looking up phone number 555-2368...
What is your phone plan? (basic/gold/unlimited) basic
Ah, the Basic package.
How many GB of data this month? 5
Wow, 5 GB is a lot of data! Maybe you should upgrade.
Your total bill is: $45.95.
Thanks for calling RobuCast, Jennifer!
Welcome to RobuCast.
What is your name? Polly
Thanks for calling RobuCast Polly!
What is your phone number? (669)221-6251
Looking up phone number (669)221-6251...
What is your phone plan? (basic/gold/unlimited) gold
Welcome Gold member. How many GB of data this month? 7
Wow, 7 GB is a lot of data! You should upgrade.
Your total bill is: $49.95.
Thanks for calling RobuCast, Polly Podcast!
Welcome to RobuCast.
What is your name? Richie$Rich
Thanks for calling RobuCast Richie$Rich!
What is your phone number? 555-0144
Looking up phone number 555-0144...
What is your phone plan? (basic/gold/unlimited) unlimited
The Unlimited plan. How many GB of data this month? 10
Wow, 10 GB is a lot of data!
Good thing you have the unlimited plan.
Your total bill is: $59.95.
Thanks for calling RobuCast, Richie$Rich!