Computer Science 202
Introduction to Programming

Fall 2013, The College of Saint Rose

Lab 6: Lottery Simulator
Due: 11:59 PM, Wednesday, December 4, 2013

For this, your last regular lab assignment, your job is to write a Java 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 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.

Simple Simulation

Your first task is to develop a simple Java program, which you should call LotterySimulation.java, 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.

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, December 4, 2013, submit your Java program for grading. There are three things you need to do to complete the submission: (i) upload a copy of your Java program (the .java file only) using Submission Box under assignment "Lottery", (ii) print a copy of your program and hand it to your instructor, and (iii) demonstrate the execution of your program for your instructor (2-day grace period for demos).

Don't forget to check your programs for compliance with the Style Guide for CSC 202 Programs before you submit!

Grading

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

> FeatureValueScore
Input parameters (file names and number of drawings) 1
Reads one number and bet amount from file 4
Reads three numbers and bet amounts from file 3
Main loop (correct number of drawings) 2
Random drawings 2
Correctly reports bet amount and number for each drawing 2
Correctly detects and reports win/loss on a drawing 4
Reports simulation results at the end 4
Simulation output to file instead of terminal 3
Using correct filenames 1
Comments 4
Naming conventions 3
Formatting 2
Bonus up to 3
Total 35