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

You\'re going to write a program that models the Littleton City Lotto (not a rea

ID: 3839106 • Letter: Y

Question

You're going to write a program that models the Littleton City Lotto (not a real Lotto game).    The program is going to allow to user to first select their lotto numbers.  The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly.

The rules for lotto work as follows:

1.  Select 7 numbers between 1 and 40

2.  Twice every week 7 numbers are drawn at random

3.  If a player matches all 7 numbers they win a million dollar prize

4.  If a player matches 6 numbers they win $100,000

5.  If a player matches 5 numbers they win $5,000

6.  If a player matches 4 numbers they win $100.

7.  If a player matches 3 numbers they win a free ticket.

Your program should work as follows.  (Note I have listed some functions you need to include in your program - you may include other functions if you would like and they make your program more readable/efficient).

Step 1:

Create an array named UserTicket to hold each of the user's lotto number selections.

Create an array named WinningNums to hold the winning lotto numbers.

Step 2:

Display the following menu:

LITTLETON CITY LOTTO MODEL:

---------------------------

1) Play Lotto

q) Quit Program

Please make a selection:

-If the selection is 1:

a.       First ask the user their name and store it in an appropriate variable.

b.      Next, call a function named getLottoPicks that asks the user to enter their 7 lotto number picks (selections) for the week.   Each of the user's lotto picks should be stored in the UserTicket array.  The lotto does NOT have duplicate numbers in it.  Find a way to not allow duplicate numbers to be picked by the user.  You may want to create another function called NoDuplicates that checks to see if the user's selection is already in the UserTicket array.  If the user enters a number already in the array, ask them to enter another number until they enter one that is not a duplicate.   This means the UserTicket array should contain no duplicate numbers.

c.       Next, call a function named GenWinNums that randomly generates the winning lotto numbers for the week based on the rules stated above and stores the winning lotto numbers in the WinningNums array (so you are going to fill the WinningNums array with random numbers between 1 and 40).  Do not allow this function to generate duplicate winning numbers (if you design your NoDuplicates function above well you should be able to re-use it to check for duplicates in the WinningNums array).   

Hint:  there are two ways to avoid having duplicate numbers in an array.  Most of you will need to use the first method.  The first method is to check the array after each number is generated or entered to make sure that number is not already in the array. If the number generated/entered is already in the array a new number should be generated/entered.  The second method involves sorting and checking that the numbers next to each other in the array after the sort are not the same - if you have taken CSIS 130 and know how to sort an array you can use this method.

d.      The next step is to check the user's lotto ticket (represented by the UserTicket array) to see if they have won any prizes in the Lotto game.  Check each number the UserTicket array to see if that number is in the WinningNums array and count how many numbers are matched.  

Display a report similar to the following showing user's lotto results - the example output below assumes the user entered a name of "Julie" when the program started.

In the "Winnings" section of the report

Display:  JACKPOT - 1 MILLION if all 7 numbers were correct

Display:  GREAT! - $100,000 if 6 numbers were correct

Display:  LUCKY YOU! - $5,000 if 5 numbers were correct

Display:  NOT BAD - $100 if 4 numbers were correct

Display:  FREE TICKET if 3 numbers were correct

Display:  SORRY NOTHING if 2 or less numbers were correct

JULIE'S LOTTO RESULTS

---------------------

WINNING TICKET NUMBERS: 35 03  01   15   10   25   22

JULIE'S TICKET              : 33 15  02   06   21   20   19

RESULTS:

--------

Number Matches: 1           

Winnings             : SORRY NOTHING

-If the selection is q:  Quit the program

-If the selection is not q and not 1:  Display an invalid selection message

Allow the user to play lotto as many times as they would like.

Explanation / Answer

/*
//Class has been written for game as per requiremnt

*/
package chegg;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class LittletonCityLotto {

//array named UserTicket to hold each of the user's lotto number selections.
int[] UserTicket = new int[7];
//array named WinningNums to hold the winning lotto numbers.
int[] WinningNums = new int[7];

String strUserFirstName = "";

public void StartGame() {
System.out.println("LITTLETON CITY LOTTO MODEL:");
System.out.println("---------------------------------------");
System.out.println("1) Play Lotto");
System.out.println("q) Quit Program");

Scanner scanner = new Scanner(System.in);

String input = scanner.nextLine();

if (input.trim().equals("1")) {

//Get User Name from user
GetUserName();
// asks the user to enter their 7 lotto number
getLottoPicks();
// randomly generates the winning lotto numbers for the week
GenWinNums();
//Display Result of lottery
LottoResult();

// Again Start the game after showing result
StartGame();
} else if (input.trim().equals("q")) {

} else {
System.out.println("Plase enter Valid selection");
StartGame();
}

}

//asks the user to enter their 7 lotto number picks (selections) for the week
public void GetUserName() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your first Name. ");
String input = scanner.nextLine();
strUserFirstName = input;
}

public void getLottoPicks() {
// ask user to enter 7 loto number between 1 to 40 and store in UserTicket array
//The lotto does NOT have duplicate numbers in it
UserTicket = new int[7];
int ArrayIndex = 0;
int selectionNumber = 1;
// Take
int ArrayLenth = 7;
for (int i = 0; i < ArrayLenth; i++) {
Scanner scanner = new Scanner(System.in);

System.out.print("Please Enter your " + selectionNumber + " number between 1 to 40: ");
int input = scanner.nextInt();

if (NoDuplicates("getLottoPicks", input)) {
UserTicket[ArrayIndex] = input;
ArrayIndex++;
selectionNumber++;
} else {
System.out.println("Please enter unique value.");
ArrayLenth++;

}
}
sortArray("getLottoPicks");
}

public void GenWinNums() {
//randomly generates the winning lotto numbers for the week
int ArrayIndex = 0;
// generate 7 loto ticket number that's why loop 7 times for 7 loto number
for (int i = 0; i < 7; i++) {
Random r = new Random();
int min = 10;
int max = 40;
int input = r.nextInt(max - min) + min;

if (NoDuplicates("GenWinNums", input)) {
WinningNums[ArrayIndex] = input;
ArrayIndex++;
}
}
sortArray("GenWinNums");
}

public void LottoResult() {

// Result report
System.out.println(strUserFirstName + "'S LOTTO RESULTS");
System.out.println("-----------------------------------");

System.out.print("WINNING TICKET NUMBERS:");
for (int i = 0; i < WinningNums.length; i++) {
System.out.print(WinningNums[i]);
System.out.print(" ");
}

System.out.println(" ");
System.out.print(strUserFirstName + "'S TICKET:");
for (int i = 0; i < UserTicket.length; i++) {
System.out.print(UserTicket[i]);
System.out.print(" ");
}
System.out.println(" ");
System.out.println("-----------------------------------");
System.out.println("RESULTS");
System.out.println("-----------------------------------");

int NumberMatched = compareArrays(WinningNums, UserTicket);
System.out.print("Number Matches: " + NumberMatched);

System.out.println(" ");
System.out.print("Winnings:");

if (NumberMatched == 7) {
System.out.println("JACKPOT - 1 MILLION");
} else if (NumberMatched == 6) {
System.out.println(" GREAT! - $100,000");

} else if (NumberMatched == 5) {
System.out.println("LUCKY YOU! - $5,000");

} else if (NumberMatched == 4) {
System.out.println("NOT BAD - $100");

} else if (NumberMatched == 3) {
System.out.println("FREE TICKET");

} else if (NumberMatched == 2 || NumberMatched < 2) {
System.out.println("SORRY NOTHING");

}

}

public int compareArrays(int[] array1, int[] array2) {
boolean b = true;
int NumberofSameTicket = 0;
if (array1 != null && array2 != null) {

for (int i = 0; i < array2.length; i++) {
if (array2[i] == array1[i]) {
NumberofSameTicket++;
}

}
} else {
b = false;
}
return NumberofSameTicket;
}

public boolean NoDuplicates(String ArrayType, int num) {
boolean blNoDuplicate = true;
// return true if not duplicate or false otherwise

if (ArrayType == "getLottoPicks") {
for (int i = 0; i < UserTicket.length - 1; i++) {
if (UserTicket[i] == num) {
blNoDuplicate = false;
}
}
}
if (ArrayType == "GenWinNums") {
for (int i = 0; i < WinningNums.length - 1; i++) {
if (WinningNums[i] == num) {
blNoDuplicate = false;
}
}
}

return blNoDuplicate;
}

public void sortArray(String ArrayType) {
if (ArrayType == "getLottoPicks") {
// sorting array
Arrays.sort(UserTicket);
}
if (ArrayType == "GenWinNums") {
// sorting array
Arrays.sort(WinningNums);
}
}

public static void main(String[] args) {
LittletonCityLotto obj = new LittletonCityLotto();
obj.StartGame();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote