Write a java program to simulate a lottery drawing

Assignment Help JAVA Programming
Reference no: EM131028708

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)

Reference no: EM131028708

Questions Cloud

Answer true or false for each question : A population forms a normal distribution with µ=80 and o=10. In this population, 42.07% of the scores greater than x=78.
Analyze individual and organizational approaches to change : The case of Welcome Israel provides another opportunity to analyze individual and organizational approaches to change(s) and the impact of those changes. The case provides a synopsis of Ofra Sherman's and Glaxo’s situations as the change was unfoldin..
Problem regarding the synonym for revenue : The data below appear in the five - year summary of a major international company. A business combination with another major manufacturer took place in 2003. The term turnover in this financial data is a synonym for revenue.
Earnings per share of common stock : Determine the earnings per share of common stock, assuming income before bond interest and income tax is $750,000. Enter answers in dollars and cents, rounding to the nearest whole cent.
Write a java program to simulate a lottery drawing : 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.
What is the influence of learning environment : What are metalinguistic skills and how do they develop across the school years? What is the influence of learning environment on language impairment
Effect of each transaction and the balances : 1. Indicate the effect of each transaction and the balances after each transaction, using the following tabular headings:
What is the value of the zero with the smaller multiplicity : Find the zero for the following polynomial function and give the multipilicty for each zero. For each zero, state whether the graph crosses the x-axis or touches the x-axis and turns around.
Use a more analytical strategy in the future : Suppose that you were hired as a data analyst by the Cleveland Browns. The Browns have indicated they would like to use a more analytical strategy in the future.  How would the Browns utilize a CRISP-DM framework if they were trying to improve the te..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Develop a menu driven console java program

Develop a Menu Driven Console Java Program to demonstrate you can use Java constructs including input/output via GUI dialogs, Java primitive and built-in types, Java defined objects, arrays, selection and looping statements and various other Java ..

  Write a main method that reads in a single string

Write a main method that reads in a single string and calls trianglePrint with that string. Write a method that uses recursion to print an input string in the shape of a triangle

  Negatively impacting health care currently

Identify and explain at least two events that are negatively impacting health care currently. Tell us why you think these items are negatively impacting the access to care, and make sure that you cite your references.

  Write a method reversefirstk

Write a method reverseFirstK that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order.

  Write a program in java that simulates a simple line editor

Write a program in Java that simulates a simple line editor which supports the following operations

  Program should assign a seat in the first class

If a person enters 1, your program should assign a seat in the first class (rows 1 - 3). If a person enters 2, your program should assign a seat in business class (rows 4 - 7). If a person enters 3, your program should assign a seat in economy class ..

  How can an applet get information about the url

How can an applet get information about the URL it was called from? What is an applet? What API changes are there for applets with JDK 1.4?

  What is a java archive

What type of output does the javadoc command generate and how do you view the output and what is a Java archive?

  Web engineering principles

web application development, Web Engineering methodology, UML-based Web Engineering (UWE), models to the expansion of web applications, Object Oriented Web Solutions (OOWS),Web Modeling Language (WebML) methodology, Object-Oriented Hypermedia Design..

  Write paper about focuses on the popularity of java

You will write a 4-5-page research-oriented paper in APA format that focuses on the "Popularity of Java"

  Create a class to represent a rectangle

Create a class to represent a Rectangle. Your class should contain instance variables for length and width, as well as member method to calculate the area and perimeter

  Client class to test implementation of the vector class

Write a client class to test your implementation of the Vector3D class thatyou implemented. Name the package in which this class is defined (projectname) vector3dapp.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd