Created
January 21, 2012 07:47
-
-
Save Justin42/1651947 to your computer and use it in GitHub Desktop.
LotteryDraw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* LotteryDraw.java | |
* | |
* A simple simulation of a lottery. | |
*/ | |
public class LotteryDraw | |
{ | |
public static void main(String[] args) | |
{ | |
int numDraws = 10; | |
LotteryTicket myTicket = new LotteryTicket(); | |
System.out.println("My lucky ticket is:"); | |
System.out.println(myTicket); | |
if (args.length != 0) | |
{ | |
numDraws = Integer.parseInt(args[0]); | |
} | |
System.out.print("Performing " + numDraws); | |
System.out.println(" draws. Good luck!"); | |
for (int i=0;i<numDraws;++i) | |
{ | |
LotteryTicket winner = new LotteryTicket(); | |
if (myTicket.matches(winner)) | |
{ | |
System.out.println("YOU WIN!!!!"); | |
System.out.println("Time to quit school."); | |
return; | |
} | |
else | |
{ | |
System.out.println("You didn't match " + winner); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment