Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help me fix this code! I'm getting constant errors. Make sure to actually test and run the program first before posting a correction! import java.util.Scanner;

help me fix this code! I'm getting constant errors. Make sure to actually test and run the program first before posting a correction!

import java.util.Scanner;

/**
* Interactive Java program to share information about favorite things.
*
* @author Williams, Stanley
* @assignment ICS 111 Assignment 04
* @date February 4, 2024
* @bugs None
*/

public class WilliamsStanley04 {

public static void main(String[] args) {
// Create a Scanner object to read user input
Scanner scanner = new Scanner(System.in);

// Ask the user if they'd like to hear about a favorite thing
System.out.println("Would you like to hear about one of my favorite things? (yes/no)");
String userResponse = scanner.nextLine().toLowerCase();

// Check user's response
if (userResponse.equals("yes")) {
// Present a list of choices
System.out.println("Great! Choose one of the following:" +
"1. Favorite Book" +
"2. Favorite Movie" +
"3. Favorite Restaurant");

// Get user's choice
int userChoice = scanner.nextInt();

// Use switch statement to handle different choices
switch (userChoice) {
case 1:
// User chose Favorite Book
System.out.println("One of my favorite books is 'The Master Key System.' It's a classic novel with a powerful message.");
break;
case 2:
// User chose Favorite Movie
System.out.println("One of my favorite movies is 'Fist of Fury.' It's a compelling story about hope and redemption.");
break;
case 3:
// User chose Favorite Restaurant
System.out.println("One of my favorite restaurants is 'Cheesecake Factory.' They serve delicious Italian cuisine.");
break;
default:
// User entered an invalid choice
System.out.println("Invalid choice. Program exiting.");
return; // Exit the program


// Ask for feedback on the chosen item
scanner.nextLine(); // Consume the newline character
System.out.println("What do you think about the chosen item? (good/okay/bad)");
String feedback = scanner.nextLine().toLowerCase();

// Provide different responses based on user feedback
if (feedback.equals("good")) {
System.out.println("I'm glad you liked it!");
else if (feedback.equals("okay")) {
System.out.println("Well, everyone has their own taste!");
else if (feedback.equals("bad")) {
System.out.println("Sorry to hear that. I appreciate your honesty!");
else {
System.out.println("Invalid feedback. Program exiting.");
return; // Exit the program

else {
// User doesn't want to hear about favorite things
System.out.println("Okay, maybe next time. Program exiting.");


// Close the scanner
scanner.close();
}
}

Step by Step Solution

3.42 Rating (146 Votes )

There are 3 Steps involved in it

Step: 1

You are missing a closing parenthesis on line 36 after Cheesecake Factory You are missing a closing curly brace on line 51 after the last else statement You should use scannernext instead of scannerne... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions