just posting from school to copy at home

Go down

just posting from school to copy at home

Post by iGod on Tue Apr 23, 2013 2:34 pm

import java.util.Random;
import java.util.Scanner;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Menu {
public static void main(String[]args){
//Declares choice as 0
int ques = 0;
int ques1 = 0;
int ques2 = 0;
int choice = 0;
//dowhile loop that contains the menu
//prompts user to enter the number
System.out.println("Enter the number of your selection.");
//displays option 1
System.out.println("1. Guessing Game");
//displays option 2
System.out.println("2. Quiz Game");
//displays option 3
System.out.println("3. Quit");
//creates a new scanner
Scanner scan = new Scanner(System.in);
//asks the user to enter in a value
choice = scan.nextInt();
if(choice == 1){
Random r = new Random();
//number is the randomly picked number
int number = r.nextInt(1001);
//tries is the amount of tries taken
int tries = 0;
Scanner i = new Scanner(System.in);
//guess is the number you input
int guess;
boolean w = false;
while(w == false){
//Prompts user for a value between 1 and 1000
System.out.println("Pick a number between 1 and 1000.");
guess = i.nextInt();
//even try you enter a wrong number add 1 to the amount of tries
//if guess is equal to the number finish
if (guess == number){
w = true;
//if guess is less than the number go to next step
}else if(guess<number){
//prints the number is to low
System.out.println("Number is to low");
//if guess is greater than the number go to the next steap
}else if(guess>number){
//prints the number is to high
System.out.println("Number is to high");
//print winner
//print the number
System.out.println("The number was " + number);
//print the amount of tries took
System.out.println("It took you " + tries + " tries.");


if(choice == 2){
System.out.println("If it's the thrid week in march who is morgan freeman?");
Scanner an = new Scanner(System.in);
ques = scan.nextInt();
if(ques == 36){
System.out.print("Correct! \n");
System.out.print("Next Question. \n");
System.out.print("Who is morgan freeman? \n");
Scanner an1 = new Scanner(System.in);
ques1 = scan.nextInt();
if(ques1 == 21){
System.out.print("Correct! \n");
System.out.print("Next Question. \n");
System.out.print("Who is the very best? \n");
Scanner an2 = new Scanner(System.in);
ques2 = scan.nextInt();
if(ques2 == 34){
System.out.print("Correct! You win. \n");


System.out.println("Wrong, you lost!");
if(choice == 3){
//displays the number that you choose
//dowhile loop continues if the choice is less than 3
while(choice < 3);

Posts : 64
Reputation : 7
Join date : 2013-02-19

View user profile http://igservers.forumotion.com

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum