Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment 8.2: String Manipulation (10 pts) Complete each of the following String manipulation problems in a file called Str.java. Your program should read in two
Assignment 8.2: String Manipulation (10 pts)
- 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:
- 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.
- 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()
- Compare the two words using compareTo to determine which one comes first alphabetically.
- 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.
- 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:
- What is your name?
- What is your phone number?
- What is your phone plan?
- 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
!".
- Reply with a greeting that displays the user's name, like "Thanks for calling RobuCast
- Phone: find out the user's phone number (String).
- Reply with a statement like "Looking up phone number
...".
- Reply with a statement like "Looking up 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,
is a lot of data! You should upgrade."
- Reply with a comment that restates the amount of data, such as "Wow,
- Total: display the total bill and say goodbye to
. - 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? jason Thanks for calling RobuCast jason! 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, jason!
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!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started