aspose file tools*
The moose likes Beginning Java and the fly likes Java Craps game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Craps game" Watch "Java Craps game" New topic
Author

Java Craps game

Tony philips
Greenhorn

Joined: May 09, 2014
Posts: 1

Can someone please help me with my HomeWork I have written the following code but can't seem to get anywhere with it. the instructor has asked that we do not use a main method only a class definition (a user-defined data type) that will instantiate a single, six-sided Die object. It will only have three members an integer variable that will store a value between 1 and 6 private int face; an object that will generate a random number Random rand = new Random, an accessor method that will return an integer value public int roll()
this method will use a random number generator, to create a random number between 1 and 6, store it in variable face, and return the value to whatever method called, the roll method



Am I close to getting this to work or should I scrap it and start over? Thanks for any time you cangive me to help!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3731
    
  16
Is this java code ?
There is no THEN or ENDIF keyword in java and the if and else keywords need to be lower case.

I think you will be better scapping it and starting again. Only write a few lines of code at a time and make sure they compile before adding any more.
If the code you added contained any functionality, test it and make sure it works before writing any more code.


Joanne
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8159
    
  23

Tony philips wrote:Am I close to getting this to work or should I scrap it and start over? Thanks for any time you cangive me to help!

Well, first up, the last half of that is NOT Java. Looks more like pseudo-code to me.

Java is CASE-SENSITIVE, so there is no such thing as "IF". There is, however, "if". There's also no such thing as "ENDIF".

Mu suggestion would be to try the tutorials, because you clearly need a bit more tuition before you'll get to a compilable program, and it would take to long to explain it all from scratch here.

HIH

Winston
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42584
    
  65
Are you trying to convert some Basic code or such that you found somewhere? "IF" and "THEN" are not part of the Java language, so in that respect I'd say you're not close to being done.

Also, in Java just about all code (actually, all code, as far you're concerned at your stage of learning) must be inside of a method. So beginning on line 23 you're out of bounds :-)

And there are a few other problems where I'm not sure what you're trying to do, like on line 9, or on line 15 where you're returning the undefined "myroll" (should probably be "Lucky", because that is otherwise unused).

I'd say, if this isn't your code to begin with, toss it and start over by implementing your own thoughts on the matter.


Ping & DNS - my free Android networking tools app
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 179
Yeah, don't mean to pile it on or anything but it looks like you're learning object oriented programming before understanding the basics. So you're several lessons/chapters behind so you should probably cram for bit before even attempting this assignment again, and yes completely scrap what you've written so far.

When you are ready for OOP, its important to know that you're code for a Die object should be separate from all the code used to actually play the game craps. Ideally you would use separate files. So you really you should have a separate class, say "Craps" that will create Die objects and call methods within the Craps class main method. I think maybe the "Die class should not have a main method" might have thrown you off into thinking that there shouldn't be a main method anywhere in your project at all.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40

Tony philips wrote:
Can someone please help me with my HomeWork I have written the following code but can't seem to get anywhere with it. the instructor has asked that we do not use a main method only a class definition (a user-defined data type) that will instantiate a single, six-sided Die object. It will only have three members an integer variable that will store a value between 1 and 6 private int face; an object that will generate a random number Random rand = new Random, an accessor method that will return an integer value public int roll()
this method will use a random number generator, to create a random number between 1 and 6, store it in variable face, and return the value to whatever method called, the roll method

Am I close to getting this to work or should I scrap it and start over? Thanks for any time you can give me to help!



As others have already stated... You need to get the pseudo code to actual Java code -- as pseudo code won't compile.

In addition to that, when your instructor said to "not use a main method only", I am pretty sure he/she meant to move code into methods, that will be called directly and indirectly from the main method. Just removing the main method header, and leaving the code without a place to put it, won't compile.

And finally, you need to visit your pseudo code again. In craps, when the point is established, the rules actually change. It isn't as simple as just roll again.

Henry
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 179
Henry Wong wrote:
In craps, when the point is established, the rules actually change. It isn't as simple as just roll again.


Yeah but creating fully functional craps is something way beyond a homework assignment. This thread actually got me thinking about it a bit. Figuring out all the different odds and bet-sizing and paying out in correctly rounded units is a bit of a nightmare.

But I guess just implementing a non-betting version of craps where if you hit you're point you just win where if you hit a seven before it you lose without any other bet options should be doable. Its actually a bit funny how crucially important "the point" is in craps and how utterly horrible a "seven-out" is, but pretty much anyone unfamiliar with the game thinks seven is the best number. I've even seen casino billboards of people gleefully rolling sevens as if it weren't the deadliest roll in the game to 99% of craps players.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40

Tyson Lindner wrote:
Yeah but creating fully functional craps is something way beyond a homework assignment. This thread actually got me thinking about it a bit. Figuring out all the different odds and bet-sizing and paying out in correctly rounded units is a bit of a nightmare.


Yeah, I am still amazed on how dealers do it... I have problems keeping track of a pass line bet with double odds, along with one or two come bets, for more than 30 minutes. The dealers have to do it for six people at a time, and for betting combinations much more complex.

Of course, for the computer, it should be easy...

Henry
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 179
Henry Wong wrote:
Tyson Lindner wrote:
Yeah but creating fully functional craps is something way beyond a homework assignment. This thread actually got me thinking about it a bit. Figuring out all the different odds and bet-sizing and paying out in correctly rounded units is a bit of a nightmare.


Yeah, I am still amazed on how dealers do it... I have problems keeping track of a pass line bet with double odds, along with one or two come bets, for more than 30 minutes. The dealers have to do it for six people at a time, and for betting combinations much more complex.

Of course, for the computer, it should be easy...

Henry


But I mean the dealers kinda cheat in that they force you to make bets where the odds payouts just require simple multiplication against your unit bet. Like if the payouts were 7 to 6 they'll very strongly encourage you to make a bet of 12 instead of 10 so they know right away the payout is 14. But for a program "strong encouragement" doesn't really work, so you have to implement a rounding scheme. I know some American casinos pay out .50 cent pieces and others don't. Just imagining how to sort all that out is a headache, at least for me.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40

Tyson Lindner wrote:
But I mean the dealers kinda cheat in that they force you to make bets where the odds payouts just require simple multiplication against your unit bet. Like if the payouts were 7 to 6 they'll very strongly encourage you to make a bet of 12 instead of 10 so they know right away the payout is 14. But for a program "strong encouragement" doesn't really work, so you have to implement a rounding scheme. I know some American casinos pay out .50 cent pieces and others don't. Just imagining how to sort all that out is a headache, at least for me.


First, I have never been to a casino that paid out in 50 cent pieces. Second, I have only been reminded of the payouts twice, and both times, I highly appreciate it when the dealer told me that I was betting incorrectly.

After all, I would like to have the option of changing my bet to $12, or lowering it to $6. Why would you want to keep my bet at $10, when the winnings would be the same as if you bet $6?

Perhaps I would feel different, if I was at a casino that paid in 50 cent pieces, and the dealer just didn't want to calculate the payouts.

Henry
Tyson Lindner
Ranch Hand

Joined: May 16, 2012
Posts: 179
Henry Wong wrote:
First, I have never been to a casino that paid out in 50 cent pieces.


Major casinos don't, but there are plenty of smaller casinos that do. Offering low stakes games with good payouts is how they compete. Another weird one is casinos that don't use .50 pieces but do use 2.50 chips.


Why would you want to keep my bet at $10, when the winnings would be the same as if you bet $6?


They aren't the same though, and this is what I'm talking about, actually understanding the rounding scheme is a real pain. With 7 to 6 odds a bet of 6 will get you 7, a bet of 12 will get you 14, but a bet of 10 will get you 11. So because of the rounding scheme, you're getting worse odds on a $10 bet. So in general, the dealers are encouraging a better bet by making you bet $12 instead of $10 (which not coincidentally makes their job easier) , but at the same time its also encouraging you to bet more money which isn't necessarily something that you want to do.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40

Tyson Lindner wrote:
They aren't the same though, and this is what I'm talking about, actually understanding the rounding scheme is a real pain. With 7 to 6 odds a bet of 6 will get you 7, a bet of 12 will get you 14, but a bet of 10 will get you 11. So because of the rounding scheme, you're getting worse odds on a $10 bet. So in general, the dealers are encouraging a better bet by making you bet $12 instead of $10 (which not coincidentally makes their job easier) , but at the same time its also encouraging you to bet more money which isn't necessarily something that you want to do.


I believe if you insist on it, the dealers will allow it. I certainly have seen some loud (and possibly drunken) players who has gotten that wager -- although, I don't understand why you would insist on getting worse than optimal odds.

Henry
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11471
    
  16

Henry Wong wrote: I don't understand why you would insist on getting worse than optimal odds.

four words: Big six, Big 8 eight.

you can make these best that pay 1:1. Basically, that a six (or eight) will be rolled before a seven.

OR, you can place the 6 (or eight), which pays $7 on a $6 if - wait for it - a six (or eight) is rolled before a seven.

I have seen dealers try and convince people not to make the Big6/8, but to put on one more dollar and place them. The gambler's arguments were basically "I don't want my money that far from me".

I asked the dealer if I could put $1 on the other guys $5, and then when it hits I get the extra $2, but was told no.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40

fred rosenberger wrote:
four words: Big six, Big 8 eight.

you can make these best that pay 1:1. Basically, that a six (or eight) will be rolled before a seven.

OR, you can place the 6 (or eight), which pays $7 on a $6 if - wait for it - a six (or eight) is rolled before a seven.


Isn't the first rule of craps... if the space looks nice and big, don't bet on it. It's a trick...

Henry
 
 
subject: Java Craps game