Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 a description of the program in the 'short description of program' section.

Step by Step Solution

3.31 Rating (163 Votes )

There are 3 Steps involved in it

Step: 1

Certainly Heres an example code that fulfills the requirements youve mentioned import javautilScanner Interactive Java program to share information ab... 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

Computer Organization and Design The Hardware Software Interface

Authors: David A. Patterson, John L. Hennessy

5th edition

124077269, 978-0124077263

More Books

Students also viewed these Programming questions

Question

Describe five of G. Stanley Halls major achievements.

Answered: 1 week ago