I have my first computer science project due and it was really easy as it was just a small review of what we did last semester but I was wondering if someone could check for logic errors in this program. It is a game of craps with a little betting thrown in.
[quote]70 pts: Simulate the dice game Craps for 100 rolls, recording the number of wins & losses. Output each roll, and wins/losses as you go, then the number of wins/losses at the end. [Rules: You win if the first roll is a natural (7, 11) and lose if it is craps (2, 3, 12). If a point is rolled (4, 5, 6, 8, 9, 10), it must be repeated before a 7 is thrown in order to win. If 7 is rolled before the point, you lose.]
85 pts: Add wagering to Craps, beginning your simulation with $100 cash, betting $5 each time. Roll until you run out of money (cash==0). In addition to showing wins/losses, count the number of rolls.
100 pts: Add strategy - Begin with $1000, betting $5 on the first roll. If you lose, double your bet. If you win, reset the bet to $5. Roll 100 times or until you run out of cash. Count wins, losses, and report your total cash at the end.[/quote]
That is the rubric, I guess. I went for the full 100pts but I don't know much about craps or the odds involved so I can't tell if there are any logic errors. Maybe you guys could double check it.
[quote]
public class project1 {
public static void main(String[] args)
{
int wins=0 , losses=0, total=0 , point=0 , cash =1000 , bet=5;
Dice[] hand = new Dice[2];
hand[0] = new Dice();
hand[1] = new Dice();
//for 100 rolls
for (int x=0; x<100; x++)
{
hand[0].roll();
hand[1].roll();
//sum them
total = hand[0].getValue() + hand[1].getValue();
// if (7 or 11) , WIN!
if (total == 7 || total==11)
{wins++;
cash +=bet;
bet = 5;
}
// else if (2,3,12) LOSE!
else if (total ==2 || total==3 || total==12)
{
losses++;
cash -=bet;
bet = bet * 2;
}
//else
else
{
int roll2=0;
point = total;
//roll until you hit 7 LOSE!
while (roll2!=7 && roll2 != point)
{
hand[0].roll();
hand[1].roll();
roll2 = hand[0].getValue() + hand[1].getValue();
}
//OR you hit your "point" WIN!
if (roll2==point )
{
wins++;
cash +=bet;
bet = 5;
}
else
{
losses++;
cash -=bet;
bet = bet * 2;
}
}
}
System.out.println("Out of 100 rounds , you had " + wins + " wins and " + losses + " losses");
System.out.println("You have " + cash +" dollars after 100 rolls");
}
}
[/quote]
Dice class
[quote]import java.util.*;
public class Dice
{
private int value;
Random rand = new Random();
public int roll()
{
//roll the dice , store in value
value = rand.nextInt(6)+1;
//return the value
return value;
}
public int getValue()
{
return value;
}
}[/quote]
Thanks!
-
Oh, actually, one thing. Does your code account for the fact you could run out of money before roll 100? It doesn't look like it does.
-
I gave that a quick glance and, while looking like a few things might be able to be a bit more... elegant, it looks functional. Should get you the desired results. I'd check, but my laptop is far less than capable of downloading/running JGrasp in its current state. From the quick readthrough I did, however, it looks good.
-
No one? I thought around 90% of you guys wanted to be programmers or help with game design in some way.
-
░░░░░░░░░░▄▄▄▄▄▄ ░░░░░░░░▄▀█▀█▄██████████▄▄ ░░░░░░░▐██████████████████▌ ░░░░░░░███████████████████▌ ░░░░░░▐███████████████████▌ ░░░░░░█████████████████████▄ ░░░▄█▐█▄█▀█████████████▀█▄█▐█▄ ░▄██▌██████▄█▄█▄█▄█▄█▄█████▌██▌ ▐████▄▀▀▀▀████████████▀▀▀▀▄███ ▐█████████▄▄▄▄▄▄▄▄▄▄▄▄██████▀ ░█▒▀▀████████████████████▀▒▒▐▌ ░█▒▐▒▒▐▄▄░▌░░▐▒▄▄▐▒▌▒▒▒▒▒▒▒▒▐▌ ░▐▌▌▒▒▌██▌░░░░▀▄▒▐▀▌▒▒▒▒▐▒▒▒█ ░░█▐▒▒▌▌█▌░░░░░▀▄▐▌▌▒▒▒▒▌▒▒▐▌ ░░░█▒▐▌▐░▌░░░░░█░▀█▌▒▒▒▐▐▒▒█ ░░░▐▌▐▌░▀░░▌░░░░▀▀░▌▒▒▒▐▒▄▐▌ ░░░░▐▐░░░░░░░░░░░░░▌▒▒▌▌▌▌█ ░░░░░▐█▄░░░░░▄▄░░░▐▒▒▐▐▒▀ ░░░░░░████▀▄▄▄▄░░██▒▄█▌ ░░░░░░░██▌▌░▄█▐░░▌▐▄▀▌ ░░░░░░░░█░▄▀▒▄▀▄▀▒▌▒▀▄ YOU HAVE BEEN VISITED BY THE ANIMU FACE OF BETA COPY AND PASTE THIS IN 3 THREADS OR YOU WILL BECOME A FEDORA
-
{u r a fag() }
-
Edited by Legend Onyx Taco: 8/31/2013 7:30:16 PMTS;WI Too stupid; wasn't interested.
-
*Had to program 3 casino games in java for final project.* *Craps was one of them.* I would help, but I won't for a couple reasons. The first one is a program that small you should be able to check yourself. Two I don't have the necessary program installed on this computer to run that code and I don't feel like looking at it in order to find errors since running it is just far easier. Finally you are consistently an ass to people on here and as a result I don't feel like helping.
-
I am just starting an intro to java class, so I can't help. If it was BASIC, well that would be a different story...
-
May this help you in your studies
-
I can make a program that says hi in java. That's about it.