This will make no sense to most of you xD just pretend there are indents
import javax.swing.*;
import java.util.Random;
public class NumberGame
{
public static void main(String args [])
{
String level;
int num;
num = 0;
Random x = new Random();
String guess;
int g;
int tries = 0;
int y;
String triesMessage = "You took " + tries;
String minInput;
String maxInput;
int min;
int max;
int a;
String input;
int b = 0;
int c;
int d;
while (num >= 0)
{
switch (num)
{
case 0 :
level = JOptionPane.showInputDialog(null, "Input a number.
1 = range of 0-100
2 = set your own range
3 = have the computer guess your number
4 = quit");
num = Integer.parseInt(level); //allows user to choose level or quit
break;
case 1 :
JOptionPane.showMessageDialog(null, "You chose to use the default range of 0-100");
y = x.nextInt(101);
tries = 0;
do
{
tries = tries + 1;
guess = JOptionPane.showInputDialog(null, "What number do you guess?");
g = Integer.parseInt(guess);
if (g < y)
JOptionPane.showMessageDialog(null, "You guessed too low!");
if (g > y)
JOptionPane.showMessageDialog(null, "You guessed too high!");
if (g == y)
{
JOptionPane.showMessageDialog(null, "You guessed correctly! Congratulations!");
triesMessage = "You took " + tries + " tries";
JOptionPane.showMessageDialog(null, triesMessage);
}
}
YOU ARE READING
Emily's Bio || Diary || Journal 2
عشوائيThis is a continuation of the other journal. I generally update every day when something happens. WARNING: this is very depressing and sad because I have depression. I did make a suicide attempt at the beginning of this book so if you don't like th...
