JavaScript is required to use Bungie.net

OffTopic

Surf a Flood of random discussion.
Edited by colbyrules8: 8/31/2013 6:49:27 PM
10

Java savvy people come here.

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!

Posting in language:

 

Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

View Entire Topic
  • *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.

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

    3 Replies
    You are not allowed to view this content.
    ;
    preload icon
    preload icon
    preload icon