Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment you will create a console (standalone) application. This prog

ID: 3697109 • Letter: I

Question

In this assignment you will create a console (standalone) application. This program will allow you to select Powerball numbers. For the first 5 numbers you will be requested to enter a number that is greater than zero and less than 70 since the first 5 numbers on the Powerball lottery must be between1-69. However, there’s a catch! Each of these five numbers must be different. The following figure shows a sample screenshot: When any of the first five numbers entered is less than 0 or greater 69 the user will receive a message to this effect and will be asked to reenter the number. You will create the code that will display one message when a number that is less than 1 is entered and a different message will display when the number entered is greater than 69. For example, if the user enters zero you might display the message: “The number must be greater than zero. Please reenter the number.” If the number is the same as any number entered before it (with the exception of the Powerball number, which is the last number entered) the user will receive a message to this effect and will be requested to reenter the number. This is the same for the second through fifth numbers. When entering the Powerball number, if the number entered IS NOT between 0 and 26, the user will receive a message to this effect and asked to reenter the number. One message will display if the number entered is less than 1, and a different message if the number entered is greater than 26. The following MUST be included in the program: • You must have multiple classes. One class must include the accessor/mutator methods, a readInput() method and a writeOutput() method. You will not use the mutator methods but I want you to include them within your code in order to demonstrate your knowledge of how to create them. Name this first program “Powerball.java”. The values of the first five numbers must be saved within an array. The first element of the array will equal the first number entered, the second element of the array will equal the second number entered, etc. However, the number entered is not to be added to the array unless it is both unique from the other numbers entered, and it also falls within the correct range of numbers. • The second program is to be named “PowerballTest.java” and will be responsible for creating a Powerball object and invoking the readInput() and writeOutput() methods located in the Powerball class. THE ANSWER MUST BE IN C# CODE NOT JAVA

Here is the screen shot

Please enter number 1 which should be > 0 and less than 70

0

Number 1 must be greater than zero

Please enter number 1 which should be > 0 and less than 70

70

Please enter number 1 which should be > 0 and less than 70

1

Number 1 is 1

Please enter number 2 which should be > 0 and less than 70

70

Number 1 must be less than 70

Please enter number 2 which should be > 0 and less than 70

0

Number 2 must be greater than zero

Please enter number 2 which should be > 0 and less than 70

70

Number 2 must be less than zero

Please enter number 2 which should be > 0 and less than 70

1

Number 2 must be different from number1

Please enter number 2 which should be > 0 and less than 70

2

Please enter number 3 which should be > 0 and less than 70

0

Number 3 must be greater than zero

Please enter number 3 which should be > 0 and less than 70

70

Number 3 must be less than 70

Please enter number 3 which should be > 0 and less than 70

1

Number 3 must different from numbers 1 and 2.

Please enter number 3 which should be > 0 and less than 70

2

Number 3 must different from numbers 1 and 2.

Please enter number 3 which should be > 0 and less than 70

3

Please enter number 4 which should be > 0 and less than 70

0

Number 4 must be greater than zero

Please enter number 4 which should be > 0 and less than 70

1

Number 4 must different from numbers 1 - 3.

Please enter number 4 which should be > 0 and less than 70

2

Number 4 must different from numbers 1 - 3.

Please enter number 4 which should be > 0 and less than 70

3

Number 4 must different from numbers 1 - 3.

Please enter number 4 which should be > 0 and less than 70

4

Please enter number 5 which should be > 0 and less than 70

0

Number 5 must be greater than zero

Please enter number 5 which should be > 0 and less than 70

1

Number 5 must different from the other numbers

Please enter number 5 which should be > 0 and less than 70

2

Number 5 must different from the other numbers

Please enter number 5 which should be > 0 and less than 70

3

Number 5 must different from the other numbers

Please enter number 5 which should be > 0 and less than 70

4

Number 5 must different from the other numbers

Please enter number 5 which should be > 0 and less than 70

5

Please enter a number that is > 0 and less than 27 for your lucky Powerball number

0

The Powerball number must be greater than zero

Please enter a number that is > 0 and less than 27 for your lucky Powerball number

27

The Powerball number must be less than 27

Please enter a number that is > 0 and less than 27 for your lucky Powerball number

1

Your power ball numbers are 1 2 3 4 5 and the Powerball number is 1

Explanation / Answer

public static class RandomHelper { private static int _seedCounter = new Random().Next(); [ThreadStatic] private static Random _rng; public static Random Instance { get { if (_rng == null) { int seed = Interlocked.Increment(ref _seedCounter); _rng = new Random(seed); } return _rng; } } } public struct LotteryNumbers { public int[] RegularNumbers; public int PowerBall; public LotteryNumbers(int[] regularNumbers, int powerBall) { RegularNumbers = regularNumbers; PowerBall = powerBall; } } private LotteryNumbers GetLoterryBalls() { int[] result = new int[5]; Random r = RandomHelper.Instance; for (int i = 0; i < 5; i++) { int foo; do { foo = r.Next(1, 70); //1-59 for the regular balls } while (result.Contains(foo)); //no duplicate values result[i] = foo; } int powerBall = r.Next(1, 27); //1-35 for powerball Array.Sort(result); //not necessary but makes displaying nicer return new LotteryNumbers(result, powerBall); } LotteryNumbers quickPick = GetLoterryBalls(); LotteryNumbers lottery = GetLoterryBalls(); int matchingNumbers = quickPick.RegularNumbers.Intersect(lottery.RegularNumbers).Count(); bool powerBall = (quickPick.PowerBall == lottery.PowerBall);