Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help making the following code so that you can pick your own lottery numbers and the random winning numbers that are picked each

I need help making the following code so that you can pick your own lottery numbers and the random winning numbers that are picked each week are shown

import java.util.*; enum lottryDays {

WED, SAT

} public class Megabucks {

private static int winning_count = 0;

public static int weeks = 52;

public static int randomNumber() {

return (int) (1 + 41 * Math.random());

}

public static void main(String[] args) {

List patronsNumber = new ArrayList<>();

while(patronsNumber.size()!=6) {

int number = randomNumber();

if(patronsNumber.contains(number)) {

}else {

patronsNumber.add(number);

}

}

System.out.println("Patrons number are " + patronsNumber);

for (int i = 0; i < weeks; i++) {

for (lottryDays val : lottryDays.values()) {

MegaBucksRC draw = new MegaBucksRC();

if (draw.hasWon(patronsNumber)) {

winning_count++;

System.out.println("6 of 42");

} else {

String res = draw.matches(patronsNumber)+" of 6 Numbers";

if(draw.containsBonusNumber(patronsNumber)) {

res = res+"+bonus number";

}

System.out.println(res);

}

}

}

System.out.println("Lotteries Won: "+winning_count);

} }

import java.util.*; public class MegaBucksRC {

private int[] frequencyArray = new int[42];

private ArrayList numbers = new ArrayList<>();

public MegaBucksRC() {

while (numbers.size() != 7) {

int number = randomNumber();

if (!numbers.contains(number)) {

if (numbers.size() < 6) {

updateFrequency(number);

}

numbers.add(number);

}

}

}

private void updateFrequency(int i) {

frequencyArray[i] = 1;

}

private int randomNumber() {

return (int) (1 + 41 * Math.random());

}

public int matches(List patronsNumber) {

int count = 0;

boolean res = false;

for (int i = 0; i < patronsNumber.size(); i++) {

if (patronsNumber.contains(numbers.get(i))) {

count++;

}

}

return count;

}

public boolean containsBonusNumber(List patronsNumber) {

return patronsNumber.contains(numbers.get(6));

}

public boolean hasWon(List patronsNumber) {

boolean res = false;

if(matches(patronsNumber)==6) {

res = true;

}else if(matches(patronsNumber)==5 && containsBonusNumber(patronsNumber)) {

res = true;

}else {

res = false;

}

return res;

}

public List numbers() {

return numbers;

}

}

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions