University of Pittsburgh
Spring 2004
CS0007:  Introduction to Computer Programming
  Assignment 6:  Keno
PROJECT INFORMATION
DUE DATE
Fri Apr 2, midnight
VALUE
75 points
BACKGROUND READING
Chapter 6 JBD
helper methods

Reminder:  You are not allowed to every look at or show your program to anyone else working on the assignment.
Any help you get should come from the instructor, TA, or help provided by the university.

INTRODUCTION

Keno is a popular game in casinos and is pretty easy to play.  It is a lot like lotto.  Basically, you get a "ticket" containing the numbers between 1 and 80.  You then pick anywhere between 1 and 15 of these, then turn it in to the casino.  At some point, the "board" shows 20 randomly drawn numbers, and then you hope for lots of hits (i.e. matches between your picks and those on the board).
 

WHAT TO DO

In this assignment, you are being asked to write a program that will play keno with the user.  To simplify the task, we will say that the user will always enter 7 numbers.  Of course, there are no duplicates allowed in either the user's picks or the randomly drawn numbers. 

The program should begin by asking the user for how much to wager and then get the 7 picks.  After this, the 20 randomly chosen values are displayed, and the program tells the user the results.  For each dollar wagered, the payoff is as follows:

# Hits
Winnings per $1
7
$12,000
6
$200
5
$20
4
$1
3 or less
$0

Suppose the user wagers $50 and has 5 hits.  In other words, of the 7 numbers chosen, 5 of them were present in the 20 randomly drawn values.  In this case, the user wins $20 for each $1 wagered, meaning a $1000 payoff. 
 
OUTPUT

Here is a sample run of what your program might look like to the user.

$ java keno
Welcome to Keno!
How much would you like to wager? (Whole # only):  20
Please enter an integer between 1 and 80: 14
Please enter an integer between 1 and 80: 21
Please enter an integer between 1 and 80: 32
Please enter an integer between 1 and 80: 21
Sorry, you picked that one already.
Please enter an integer between 1 and 80: 23
Please enter an integer between 1 and 80: 88
Please enter an integer between 1 and 80: 8
Please enter an integer between 1 and 80: 12
Please enter an integer between 1 and 80: 76
Your picks: 14 21 32 23 8 12 76
Board: 7 14 18 20 25 27 32 38 40 41 50 53 56 62 63 68 74 77 80

You had 2 matches with the board.
Sorry, you did not win any money.
$


 
PROGRAM REQUIREMENTS

This program can get fairly involved, especially if you don't plan it out first.  These requirements are important to keep in mind not only because of your program will be graded, but also so you can finish the project.
  • Use good style (indentation, structure, appropriate variable names, and comments)
  • You need to have two arrays - one to hold the user's picks and one to hold the randomly drawn picks.
    • Arrays of ints will certainly work, but another option is to use an array of booleans indexed from 1 to 80. 
  • You'll need several methods to handle many of the sub-tasks involved.  Before you start, plan out all the big steps based on the discussion above and the sample run.  Each part can be handled with a method.  To get you started, write methods to:
    • load the user's array (do not allow duplicates)
    • randomly load the game picks (do not allow duplicates)
    • print the contents of these arrays
    • ... (you do the rest)
  • Use final ints to control the upper bounds.  You can declare these just before main() so all methods can use them.  You may not declare your variables here - it is important to not do this.  For example, you could use these:
    • static final int NUM_UPICKS = 7;
    • static final int BOARD_MAX = 80;
    • static final int GAME_PICKS = 20;
    • You will find that it is hard to win anything with these settings, so when you are testing, just change these around to increase your chance of winning.  Lowering the board max to 40, for example, will greatly increase your chances of getting hits. 
    • When you randomly determine a computer pick, use (Math.random() * BOARD_MAX) + 1  This will give you something between 1 and BOARD_MAX.  Don't forget to prevent duplicates.
Advice:
This can become overwhelming if you are not careful.  If you have not studied the book's examples and ran small programs with arrays, you will probably fail miserably at this program.  PLEASE PREPARE YOURSELF!!!

My advice is to work a little at a time and set small goals.  It is not trivial preventing duplicates in these arrays, so set that goal for yourself one night.  Sit down and write a program that will load 7 values into an array and skip repeats or numbers out of range.  The same idea can be reused when you load the random picks later, only difference is that you are getting the numbers randomly.

At the top of this program I have included a link to code that you may find helpful.  You can copy these into your program and just call them.  They handle some of the little details that you will be facing in this program.

TURNING THE ASSIGNMENT IN

As usual, copy your source (.java) and executable (.class) files into the assignment6 handin directory.  Please try to avoid copying other files over.
 
Last Updated:3/18/04 by H. Chad Lane
© 2003-2004 University of Pittsburgh