Results 1 to 3 of 3
Thread: Slot Machine Game
- 09-17-2011, 10:05 PM #1
Member
- Join Date
- Sep 2011
- Location
- Washington DC
- Posts
- 51
- Rep Power
- 0
Slot Machine Game
hi, it is me again. Need some help with a program of mine. I have mostly finished it, just need some help with the errors i am receiving

for some reason, when it gets to the bolded part, I cannot enter any imput when debugging. Does anyone know what is wrong..?Java Code:import java.util.*; public class ansher_slots { public static void main(String [] args){ Scanner keyboard =new Scanner(System.in); int num=0; int bet = 0; int won_amount=0; int loopvar=1; System.out.println("The World Series of Slots Machine! It's Game Time!"); System.out.print("How many tokens are you buying? "); int tokens = keyboard.nextInt(); [B] do{[/B] [B] System.out.print("You have " + tokens + " tokens. Would you like to play? (y/n): ");[/B] [B] String play_question = keyboard.nextLine();[/B] if(play_question=="y"){ loopvar=2; do{ System.out.print("How much would you like to bet? "); bet = keyboard.nextInt(); if(bet>tokens || bet<0){ System.out.print("ERROR: You entered more tokens than you have or a negative number."); num=1; } }while(num==1); System.out.print("You have bet " + bet + " tokens...Buena Suerte!"); int ran1=spin(); int ran2=spin(); int ran3=spin(); System.out.println("SPIN: [" + ran1 + "] [" + ran2 + "] [" + ran3+ "]"); won_amount=determineWin(bet, ran1, ran2, ran3); tokens = tokens + won_amount; if(won_amount>0){ System.out.println("You won " + won_amount + " tokens!! WOW!!"); } else if(won_amount==0){ System.out.println("Sorry Big shot, You didn't win anything..Better luck next time!"); } } else{ System.exit(-1); } }while(loopvar==2); } public static int determineWin(int bet, int ran1, int ran2, int ran3){ if(ran1==7 && ran2==7 && ran3==7){ return bet*3; } else if(ran1==2 && ran2==2 || ran2==2 && ran3==2 || ran1==2 && ran3==2){ return bet*2; } else if(ran1==5 || ran2==5 || ran3==5){ return bet; } else{ return 0; } } public static int spin(){ Random randGen= new Random(); int random_number=0; random_number=randGen.nextInt(9)+1; return random_number; } }
This is current output:
The World Series of Slots Machine! It's Game Time!
How many tokens are you buying? 125
You have 125 tokens. Would you like to play? (y/n):
When I try to type, nothing happens...
- 09-17-2011, 10:08 PM #2
Member
- Join Date
- Sep 2011
- Location
- Washington DC
- Posts
- 51
- Rep Power
- 0
Re: Slot Machine Game
so I added Keyboard.nextline(); befre the next "nextInt()" and it seemed to work! But when it gets to this part:
It is terminated for some reason, this is output:Java Code:[FONT=monospace] if(play_question=="y"){[/FONT] loopvar=2; do{ System.out.print("How much would you like to bet? "); bet = keyboard.nextInt();
The World Series of Slots Machine! It's Game Time!
How many tokens are you buying? 125
You have 125 tokens. Would you like to play? (y/n): y
- 09-17-2011, 10:55 PM #3
Similar Threads
-
Complete Game Engine for beginner and intermediate game programmers
By rdjava in forum Java GamingReplies: 1Last Post: 06-02-2011, 09:29 AM -
transfering the file from one machine to another machine using ftp in java
By rkraj in forum Java SoftwareReplies: 0Last Post: 02-07-2011, 01:27 PM -
Slot Machine Project
By nemoisback66 in forum New To JavaReplies: 11Last Post: 11-17-2010, 03:20 PM -
Getting name/ip of a machine
By Java Tip in forum Java TipReplies: 0Last Post: 03-02-2008, 07:11 PM -
Communication with Expansion Slot Compact Flash device on PDA
By percivalwcy in forum CLDC and MIDPReplies: 0Last Post: 07-25-2007, 09:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks