Question: This is introduction on java and how to use loops so please be basic and simple. Thank you Scenario You go to an arcade with

This is introduction on java and how to use loops so please be basic and simple. Thank you

Scenario You go to an arcade with 20 tokens, and each game costs 2 tokens. What loop should you use, and why? Every time you play, you should show the number of tokens you have left. Before the loop starts, display how many tokens you have available to play with. After the loop ends, state how many tokens you have left.

Scenario You are playing a guessing game with your little cousin. She writes down her favorite color on a piece of paper, and folds it over. Then, she asks you to guess her favorite color. What loop should you use for that, and why? In the loop, ask the user to guess the favorite color, and compare it to the actual favorite color variable that had been initialized before the loop began. In the loop, display whether the users guess was correct or not.

Scenario You go to an arcade with 100 tokens, and each game costs a variablenumber of tokens. What loop should you use, and why? Before the loop begins, display how many tokens you have available. Inside the loop, ask the user how many tokens does the next game cost, and subtract that amount from the total tokens if it is less than or equal to the total tokens. Then, state how many tokens are still left.

Scenario You go to an all-you-can-eat buffet. You are trying to eat only until you are no longer hungry. What loop should you use, and why? The loop should ask the user if he/she is still hungry, and if the answer is yes then the loop should display eat more.

Scenario It is Saturday night, and you are watching the Lottery draw for Fantasy Five. You get inspired to write a program to generate 10 lotto tickets, each ticket has 5 Lotto numbers. What loop should you use, and why? Note: To generate the 5 lotto numbers, you could create another loop inside the outer loop. This is called a nested loop. Otherwise, you will have to duplicate the method to generate a random number 5 times.

Note: Use JOptionPane for this entire Lab.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!