Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Lottery Game (15 Numbers). [5 Points] Design and implement a Java program that generates non-repeating 15 random non-repeating positive integer numbers from 1

image text in transcribed

image text in transcribed

Part 2: Lottery Game (15 Numbers). [5 Points] Design and implement a Java program that generates non-repeating 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Static methods you need to implement: Define static methodinitialize() that takes array lotterNumbers[] as a parameter and assigns O to each element of the array. Hint: Array elements are assigned 0, which is outside of lottery numbers' range, to distinguish elements that have not been given lottery numbers yet. Passing an array as a parameter and its initialization is done the way I showed you in class. Define a search static method check()that takes a number and the array lotterNumbers[] as parameters and returns true if the number matches one of the elements in the array, or false if none of the 15 elements That is, in the static method, you should write the code that iterates over the array looking for the number passed as the parameter. You may assume that the number that check() is looking for is always positive. Hint: Looking for the match is similar to looking for the minimum. Define a static method generate()that takes the array lotterNumbers as a parameter and fills it with 15 random integers whose values are from 1 to 999. The numbers should not repeat (essential). Hint: Use the class Random we studied earlier in class to generate appropriate random numbers from 1 to 999 and fill the array. Before the selected number is entered into the array lotterNumbers, call static method check() to make sure that the new number is not already in the array. If it is already there, ignore it and select another number. The pseudocode for your generate() static method may be as follows: 1.declare a variable "number of selected lottery numbers so far", and 2.initialize this variable to zero 3.while (the_number_of_selected_elements is less than the array size) 3.1. select a new random number 3.2. call check() to see if this random number is already in the array 3.3. if the new random number is not in the array 3.3.1. increment the number of selected elements 3.3.2. add the newly selected element to the array Define static method input()that asks the user to enter a single number from 1 to 999 and returns this value. Define static method printOut()that outputs the selected numbers and user input. The pseudocode your method main() should be as follows: Public static void main main(String [] args) { declare array and other variables initialize (...) // fill array with O generate(...) // select 15 non-repeating random numbers input ...) // get user input use check () to compare user input against lottery numbers and output whether user won printOut...) // outputs seleced lottery numbers Note: A program that processes each element of the array separately (i.e. accesses all 15 elements of the array for assignment or comparison outside a loop) is inefficient and will result in a poor grade. Note 2: use the Array.length to retrieve the size of your array in the methods. Make sure your programs adhere to proper programming style (e.g., good identifiers, comments, etc.) Post your questions on Piazza for prompt support

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

=+Describe your point of view.

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago