Using java
use a while loop
use JOptionPane
Scenario – You go to an arcade with 100 tokens, and each game costs a variable number of tokens. 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.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
// Arcade.java
import javax.swing.JOptionPane;
public class Arcade {
public static void main(String[] args) {
// initializing tokens to 100
int tokens = 100;
// displaying a message showing tokens before game begins
JOptionPane.showMessageDialog(null, "You have " + tokens
+ " tokens, the game is about to start");
// loops as long as there is a token available
while (tokens > 0) {
try {
//reading number of tokens using an input dialog box
int num = Integer
.parseInt(JOptionPane
.showInputDialog("How many tokens does the next game cost? ("
+ tokens + " available)"));
//checking if number exceeds the available tokens
if (num > tokens) {
//displaying error message
JOptionPane.showMessageDialog(null,
"Sorry, that's more than what you have!");
} else {
//subtracting num from tokens
tokens -= num;
}
} catch (Exception e) {
//non numeric input
JOptionPane.showMessageDialog(null,
"Sorry, that's an invalid input!");
}
}
//after exiting loop, displaying a good bye greeting.
JOptionPane.showMessageDialog(null,
"You have no tokens left, thank you for playing!");
}
}
/*OUTPUT (partial)*/




Using java use a while loop use JOptionPane Scenario – You go to an arcade with...
please do num 3,4 and 5.
Practice on Selecting the Appropriate Loop: You are playing a she guess lfavorite color variable guess the favorite color, and com user N e up began. In the loop, display w WaS COfrect or not the 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...
Write a java program that makes use of the ‘DO WHILE ’ loop. The program asks a user to enter information about several of their friends. The information is their last name, the state they live in, their age, and their expected graduation year. After you enter one friend, write out each individually. You must use JOptionPane to input the 4 fields, and to output the 4 fields. Refer to the textbook Code Listing 4-6 to see how to use...
.Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...
NOTE: Use JOptionPane NOT Scanner Please Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user...
A simple game of chance Using a while loop write a simple coin flip game. Specifics: The user starts with a bank of $10.00 It costs a dollar to play A correct guess pays $2.00 The while loop is used for the game loop. It should ask if the user wants to play. The while loop will check for a value of 'Y' or 'N'. You should also allow for lower case letters to be input. You MUST prime the...
For this lab you will write a Java program using a loop that will play a simple Guess The Number game. Th gener e program will randomly loop where it prompt the user for a ate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a r has guessed the correct number, the program will end with a message indicating how many guesses it took to get the right answer and a...
I have to use java programs using netbeans. this
course is introduction to java programming so i have to write it in
a simple way using till chapter 6 (arrays) you can use (loops ,
methods , arrays)
You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...
Create a function without using import scanner and you must create and use a java method in this assignment | x+2 x<= 2 f(x) = | | -x^2 +2x +2 x>2 Name the function f Ask the user to enter a double, calculate and display the resulting value of f(x) +5 pts: loop the ask-and-calculate-and-display loop Your main program should: Get a number (x) Use f to calculate a value of the function Display the result (optional) loop back and...
Using the Phyton program; Write a program using loop (use days of the week as a list) to ask the user to enter the total hours spend studying for each day of the week. How many hours spent studying on Monday? How many hours spent studying on Tuesday? Count and display the number of days the user 1) studied less than 4 hours. 2) studied between 4- 8 hours 3) studied more than 8 hours
I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...