The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled Java Code
Posted by: Andrew Head | October 18, 2008 @ 2:50pm
Java Code
[
Download
]
/*LuckySevens.Java simulates the game of LucySevens until all funds are depleted. 1) Rules: Roll two dice if the sum equals 7, win 4$ else lose 1$ 2) The inputs are: the amount of money the user is prepared to lose. 3) Computation: uses a Dice Class that genertaies a random number loop until the funds are depleted count number of rolls keep track of the Max amount 4) The outputs are: the number of rolls it takes to deplete the funds the max amount */ import java.util.Scanner; public class LuckySevens { public static void main(String[] args) { Scanner reader = new Scanner(system.in); int dollars, //initail number of dollars (input) count, //number of rolls to reach depletion maxDollars, //maximum amount held by the gambler countAtMax; //count when the maximum is achieved Dice die1 = new Dice(); Dice die2 = new Dice(); die1.roll(); die2.roll(); // Request the input System.out.print("How many dollars do you have? "); dollars = reader.nextInt(); // Initalize Variables maxDollars = dollars; countAtMax = 0; count = 0; //loop until the money is gone while (dollars > 0) {count++; private int side; public Dice()( side = 1; //set side to any value from 1 - 6) public int getCurrentSide()( return side; ) } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.50 / 8
264 Votes