Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Project 2: Powerball (or, Why Throwing Money at the Lottery Is a Bad Idea)

Background Information

This assignment involves simulating a lottery drawing. In this type of lottery game, the player picks a set of numbers. A random drawing of numbers is then made, and the player wins if his/her chosen numbers match the drawn numbers (disregarding the order of the numbers).

More specifically, a player picks k distinct numbers between 1 and n (inclusive), as well as one bonus number between 1 and m (inclusive). "Distinct" means that none of the first k numbers may be repeated. However, the bonus number may or may not coincide with one of the k distinct numbers. The k distinct numbers as well as the bonus number must match the drawn values for the player to win the jackpot.

The TN Lottery's Powerball game is a good example of this type of lottery. In this game, a player picks five numbers between 1 and 59, inclusive, and one "Powerball number" between 1 and 35, inclusive. Here, the number of possible lottery tickets is:

{(59 x 58 x 57 x 56 x 55) / (5 x 4 x 3 x 2 x 1)} x 35 = 175,223,510

A single ticket's chance of winning the jackpot is then 1/175,223,510, which is about 0.0000000057. To put that probability in perspective, suppose you were to sell your Harbor Town mansion for $600,000 and use the proceeds to buy Powerball tickets. Since tickets cost $2 each, $600,000 will buy you 300,000 tickets. Even with that many, your chance of winning the jackpot is still a miserably low 0.0017 - less than two tenths of one percent. Makes you think twice about buying that lottery ticket, doesn't it?

In general, for this type of lottery drawing the number of possible tickets is:

[{n x (n - 1) x (n - 2) x ... x(n - k + 1)}/ {k x (k - 1) x (k - 2) x ... x 3 x 2 x 1}] x m

The Assignment

Write a Java program to simulate a lottery drawing. Your program should allow the user to enter values for k, n, and m above. Then, ask the user to enter the numbers that s/he wishes to play (this is your program's equivalent of "buying" a lottery ticket). Store the k distinct numbers into an array, but keep the bonus number separate.

The program should compute and display the probability of winning the jackpot for the selected game. Then, it should randomly "draw" the winning numbers and determine if the user-entered numbers match. Keep in mind that the matching for the k distinct values should disregard the order of the numbers. The winning numbers should be shown, along with an appropriate message indicating whether or not the user won the jackpot. Allow the user to play as many games as s/he wants.

Error Checking

Implement error checking on all user inputs, to the extent we've discussed it in class (don't worry about data type mismatches). Error checking should repeatedly prompt for the input until the user enters a valid value. For example, the user should not be able to enter negative inputs. The user input should also be checked to see that it matches the entered values for n and m - for example, in a game where n = 59, the user should not be able to pick 60 for his/her ticket. Also make sure that you're checking for distinct inputs when the player chooses numbers - a player shouldn't be able to pick the same number more than once (with the exception of the bonus number).

Code Organization

Your program should use methods to break the code down into manageable chunks. At minimum, include the following methods (although you are welcome to add more if you want).

// Returns the probability of winning the jackpot in a lottery drawing with the
// specified parameters.
public static double jackpotChance(int k, int n, int m)

// Allows the user to enter k distinct integers between 1 and n. Must include
// error checking to ensure that each entered number is within the valid range and
// does not coincide with any previously entered number. Returns an array of
// the entered numbers.
public static int[] enterNumbers(int k, int n)

// Makes the computer draw k distinct random integers between 1 and n. Returns an // array of the drawn numbers.
public static int[] drawNumbers(int k, int n)

// Returns whether the two arrays a and b contain the same elements, without
// regard to order. For example, if a = {1, 4, 3, 2} and b = {1, 2, 3, 4},
// this method should return true.
public static boolean containSameElements(int[] a, int[] b)

Java, Programming

  • Category:- Java
  • Reference No.:- M91753226

Have any Question?


Related Questions in Java

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As