I'm still getting the same 5 error codes and this is like the 3rd or 4th time
Question:
I'm still getting the same 5 error codes and this is like the 3rd or 4th time correcting! Maybe it's time to write an entire new program. Also make sure to actually verify and run this program instead of assuming that it works and won't have any errors because this is around the 5th attempt to get a working Java program.
Here's the same error codes:
----jGRASP exec: javac -g WilliamsStanley04.java
WilliamsStanley04.java:75: error: reached end of file while parsing
scanner.close();
^
WilliamsStanley04.java:69: error: reached end of file while parsing
else {
^
WilliamsStanley04.java:65: error: reached end of file while parsing
else {
^
WilliamsStanley04.java:63: error: reached end of file while parsing
else if (feedback.equals("bad")) {
^
WilliamsStanley04.java:61: error: reached end of file while parsing
else if (feedback.equals("okay")) {
^
5 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
----------------------------
Here's the current code that keep giving the these 5 errors and none of the corrections have worked so far:
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();
----------------------------------------
Here's the previous directions:
If, if-else, and switch Statements
Objective: Create an interactive Java program that reads in user input and outputs a message dependent on user input, demonstrating the student's understanding of conditional statements.
Related SLOs:
SLO #1: Use an appropriate programming environment to design, code, compile, run, and debug computer programs.
SLO #4: Demonstrate working with primitive data types, strings, and arrays.
Instructions:
Using jGRASP, write a Java program named LastnameFirstname04.java, using your last name and your first name, that does the following:
Asks the user if they'd like to hear about one of your favorite books/movies/restaurants/(whatever you want). If the user agrees, continue with the program. If not, let the program end.
Note: the program must end completely. In other words, you should see " ----jGRASP: operation complete."
If the user says they want to hear about one of your favorite things, present the user with a list of at least 3 choices. After the user chooses one item to hear about, print a few sentences about that item.
After you have told the user about the thing they chose, ask the user for feedback on the item, specifying what item they had chosen. (See Example Output) Have different responses depending on what they type.
Note: Your program output does not have to follow the Example Output. The dialogue that your program has with the user can be completely different - be as creative as you wish. :)
Hint: Use nested ifs to control the flow of your program. Think about what you want to happen only if a certain condition is true.
Your program MUST:
Use an if or if-else statement
Use a nested or multi-way statement
Use a switch statement
Consider the possibility of a user not following directions. For example, if you tell them to press 1, 2, or 3, what should your program do if they press 4? As another example, if you tell them to "type yes or no" and they type YES, make sure your program will still accept that as valid input.
Actively use in-line comments stating what each section of code does
Your program must conform to the Java coding standards.
Your program should not use code/concepts we have not yet covered. You must demonstrate that you have mastered the concepts covered in class.
Remember to always begin your code with the following documentation comments:
/**
* Short description of the program.
*
* @author Last Name, First Name
* @assignment ICS 111 Assignment XX
* @date Today's Date
* @bugs Short description of bugs in the program, if any.
*/
Expected Output:
This is an example of what your program should output:
----jGRASP exec: java DoeJohn04
Hi there, what's your name?
Nikki
Hey, John! Do you want to hear about some of my favorite video games at the moment?
Enter yes to continue: yes
Okay! Which game would you like to hear about?
Press 1 to hear about Call of Duty
Press 2 to hear about Final Fantasy XIV
Press 3 to hear about Animal Crossing: New Horizons
3
Animal Crossing: New Horizons is a game for the Nintendo Switch.
In the game, you design an island and make friends with a bunch of cute animals.
You can do different activities like fish, catch bugs, and grow fruit trees.
Compared to a lot of other games, it's pretty relaxing because there isn't a ton of action or
events and you aren't pressured to do a lot of tasks in a short time.
You basically just chill with your animal friends on your little island. :)
So, what do you think?
Would you be interested in checking out Animal Crossing: New Horizons sometime?
yup, sounds great!
Really?! Awesome! Here, you can borrow my Switch and try it out! :)
Goodbye! :)
----jGRASP: operation complete.
This is another example of what your program should output:
----jGRASP exec: java DoeJohn04
Hi there, what's your name?
John
Hey, John! Do you want to hear about some of my favorite video games at the moment?
Enter yes to continue: yes
Okay! Which game would you like to hear about?
Press 1 to hear about Call of Duty
Press 2 to hear about Final Fantasy XIV
Press 3 to hear about Animal Crossing: New Horizons
100
100 ???
Uhh... Sorry, invalid input. You're supposed to type 1, 2, or 3.
If you REALLY want to hear about my 100th favorite video game, message me instead!
Goodbye! :)
----jGRASP: operation complete.
This is another example of what your program should output:
----jGRASP exec: java DoeJohn04
Hi there, what's your name?
John
Hey, John! Do you want to hear about some of my favorite video games at the moment?
Enter yes to continue: YEAAAAAH
Sorry, I needed you to type in "yes"..
Oh, well. We can try again another time!
----jGRASP: operation complete.
Criteria:
-Correct use of ifs to control program flow
-Use of nested or multiway if-else
-Switch
-Providing a different response depending on user's feedback
-Complying with Java coding standards.
-Don't forget to input and expand the description of the program in the 'short description of program' section of what it actually does.