All pastes #2119827 Raw Edit

Unnamed

public text v1 · immutable
#2119827 ·published 2012-02-18 22:56 UTC
rendered paste body
import java.util.Random;
import java.util.Scanner;


//any necessary imports

public class Casino 
{
	public static void main(String[] args)
	{
		//declare and initialize a Scanner
		Scanner in = new Scanner(System.in);
		
		//get seed value from user and use it to make the random number generator
		System.out.print("Please enter a seed value [integer]: ");
		//you may assume the user inputs an int for the seed
		int seed = in.nextInt();
		in.nextLine(); //defensive - to clear the new line
		Random rng = new Random(seed);
		
		//declare and initialize any other needed variables
		int curFund = 100;
		int rGames = 10;
		int sGames = 03;
		int games = 102;
		int userInput = -1;
		int bet = 0;

		//print initial rules
		System.out.println("Welcome to the Casino! You begin with $100.");
		System.out.println();

		
		
 
 //begin main menu loop
		
		while(curFund >= 0 && userInput != 4){
			
			//print out current finances
			System.out.println("Current money: $" + curFund);
			
			//prompt user for decision (play roulette, play slots, print report, quit game)
			System.out.println("Which would you like to do?");
			System.out.println("1: View Status Report");
			System.out.println("2: Play Roulette");
			System.out.println("3: Play Slots");
			//System.out.println("4: Play Craps");
			System.out.println("4: Quit");
			userInput = Integer.parseInt(in.nextLine());
			
			switch(userInput){
				
			//if user asked for status report
			case 1:	
				//print current game statistics
				System.out.println("Status Report:");
				System.out.println("Current Funds: $" + curFund + ", Initial Fund : $100");
				System.out.println("Number games played: " + games);
				System.out.println("Roulette: " + rGames);
				System.out.println("Slots: " + sGames);
				System.out.println();
				break;
			//if user chose to play roulette
			case 2:
				int color = -1;
				int num = -1;
				int netChange = 0;
				
				userInput = -1;
				//prompt for bet type and bet amount
				while(userInput == -1){
					System.out.println("Bet on color (1) or number (2)");
					userInput = Integer.parseInt(in.nextLine());
					if(userInput == 1){
						System.out.println("Bet on Red (1) or Black (2)");
						userInput = Integer.parseInt(in.nextLine());
						if((userInput != 1) && (userInput !=2)){
							System.out.println("Invalid input, reselect!");
							userInput = -1;
						}
						color = userInput;
					}
					else if(userInput == 2){
						System.out.println("Please enter the number you wish to bet on (0 to 36):");
						userInput = Integer.parseInt(in.nextLine());
						if(userInput > 36 || userInput < 0){
							System.out.println("Invalid input, reselect!");
							userInput = -1;
						}
						num = userInput;
					}
					else{
						System.out.println("Select 1 or 2.");
						userInput = -1;
					}
				}
				
				//System.out.println("color: "+color +". num " + num);
				System.out.println("How much do you wish to bet?");
				userInput = Integer.parseInt(in.nextLine());
				if(userInput > curFund || userInput < 0){
					System.out.println("are u stupid?");
				}
				else{
					bet = userInput;
					curFund -= bet;
					netChange -= bet;
				}
				//spin wheel 
				System.out.println("The spin:");
				int tmp = rng.nextInt(37);
				System.out.print(tmp);
				if(tmp == 0){
					System.out.print(", Green\n");
				}
				else if(tmp%2 == 1){
					System.out.print(", Red\n");
				}
				else{
					System.out.print(", Black\n");
				}
				
				//update attributes according to results
				
				if(color == -1){
					if (num == tmp){
						curFund += bet * 35;
						netChange += bet * 35;
					}
				}
				else if(tmp !=0){
					if(color == tmp%2){
						curFund += bet *2;
						netChange += bet * 2;
					}
				}
				
				
				System.out.println("Net change this game: " + netChange);
				
				break;
			//if user chose to play slots and has sufficient funds
			case 3:
		
				//spin reels
		
				//update attributes according to results
				
			//if user chose to quit
				break;
			case 4:
			
				//end game
				break;
			default:
				System.out.println("Wrong input, please select 1,2,3 or 4!");
			}
		
		//end of main menu loop
		}
		
		System.out.println("haha");
		//print end of game report
			
	}
}