Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

Lab 8: Lottery Simulator
Due: 11:59 PM, Wednesday, November 7, 2012

For this lab assignment, your job is to write a program to simulate a series of lottery drawings, keeping track of the amount spent on bets and any winnings. Then a report is made at the end indicating how much the gambler has won or lost during the simulation.

You will develop and submit both a Visual Logic flowchart and a Java program.

You may work alone or with a partner on this lab.

The Lottery "Numbers" Game

The lottery game we will be simulating is the New York Lottery's "Numbers Game". In this game, a bettor wagers on which random number between 000 and 999 will be selected that day. The payoff is 500:1, i.e., for a $1 bet, a match will result in a $500 payout. A $2 bet will result in a $1,000 payout, etc.. This sounds great to anyone who never passed 6th grade math. In reality, if you play this game long enough, you will lose half of your money.

Visual Logic Simulation

Your first task is to develop a Visual Logic flowchart, saved in a file LotterySimulation.vls, that simulates a specified number of lottery drawings, given the number to bet on and the amount of a bet. Each of these three are read in from the keyboard.

For example, if the number of drawings to simulate is 10, and the number to bet on is 284, betting $2 per drawing, a series of 10 random numbers in the 0-999 range should be drawn. For each number drawn, we keep track of the fact that another $2 has been bet. If the number came up as 284, we also record that the winnings for that drawing are $1,000, and that amount is added to the accumulated winnings. In the end, report the total amount that was bet and the total winnings, followed by a statement that reports either the net amount won, the net amount lost, or that the bettor broke even.

A lucky player might see:

But more likely...

Simplest Java Simulation

Next, convert this to Java. Same functionality. Call your Java program LotterySimulation.java.

Adding File I/O

Once that it working, your next task is to get some of your input (the number to bet on and the amount of each bet) from a file, and to write all of the program's output (other than Terminal prompts) to a file.

Your program should prompt (at the Terminal) for the name of the input file that contains the number to bet and the amount of each bet, for the name of the file that should contain the simulation output, and for the number of drawings to simulate.

You will need to create your plain text input file in the same folder as your BlueJ project. In Windows, you can use Notepad. On a Mac, TextEdit is a good choice. The file should consist of only the 2 numbers: the number to bet on and the amount of the best, on a single line, separated by a space.

Processing Multiple Bets Per Drawing

Finally, for just the last few points, extend your program so it reads 3 numbers to bet on and amounts of those bets. Place these on 3 lines, a number and a bet amount on each line. For each drawing, all 3 bets are placed and processed.

Note: given the Java constructs we have used so far, the best way to accomplish this is to introduce extra variables to store the additional numbers and bet amounts, and to add code inside your main loop that checks for all three of the numbers rather than just the one.

Bonus Opportunity

Up to 3 points of bonus are available. Come up with ideas and try them out.

Style and Documentation Reminders

Before you submit your programs, make sure they conform to our guidelines for style and documentation.

In particular, you should have a comment at the top of each class that describes your program and has your name (and that of your partner if you are working with someone), the course number and section (02 for 11:15, E1 for 4:10). You should have comments throughout your programs describing your variables and any non-obvious Java statements or groups of statements.

All identifiers (class names and variable names) should be meaningful and conform to Java's naming conventions.

Your code should be nicely formatted, with new lines after any { or }, and indented as done in class examples.

Submitting Your Work

Before 11:59 PM, Wednesday, November 7, 2012, submit your Visual Logic flowchart and Java program to Blackboard for grading. Please upload your Visual Logic file (LotterySimulator.vls) and your Java source file (LotterySimulator.java - upload the one with the .java file extension, not the .class, .ctxt, package.bluej or README files).

Grading

This assignment is worth 50 points, which are distributed as follows:

> FeatureValueScore
Flowchart input parameters 2
Flowchart main loop (correct number of drawings) 2
Flowchart random drawings 2
Flowchart correctly reports bet amount and number 2
Flowchart correctly detects and reports win/loss on a drawing 3
Flowchart reports simulation results at the end 4
Java input parameters (file names and number of drawings) 1
Java reads one number and bet amount from file 4
Java reads three numbers and bet amounts from file 3
Java main loop (correct number of drawings) 2
Java random drawings 2
Java correctly reports bet amount and number for each drawing 2
Java correctly detects and reports win/loss on a drawing 4
Java reports simulation results at the end 4
Java simulation output to file instead of terminal 3
Using correct filenames 1
Comments (in Java only) 4
Naming conventions (in both) 3
Formatting (in Java only) 2
Bonus up to 3
Total 50