Practice on Selecting the Appropriate Loop:
1.)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. After the loop ends, state how many tokens you have left.
2.)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 user's guess was correct or not.
3.)Scenario - You go to an arcade with 100 tokens, and each game costs a variable number 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.
4.)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.
5.)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. The outer loop is for the number of tickets, and the inner loop is for the number of Lotto numbers on each ticket. The output should look like this, where - stands for the randomly generated number between 1 & 60, and stands for the remaining tickets.
Ticket 1: -- -- -- -- --
Ticket 2: -- -- -- -- --
…
Ticket 10: -- -- -- -- --
Write a program to demonstrate each of these scenarios. These loops are required to be written in 1 program, worth 20 points per loop. Note: Use JOptionPane for this entire Lab.