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

Please help me with an exact code in JAVA and give me a code that will work perf

ID: 3592236 • Letter: P

Question

Please help me with an exact code in JAVA and give me a code that will work perfectly in Eclipse. That is all everything I have. Thanks

Selection:s Discussion- Selections Based on a lottery winning you are required to create a pseudo code on the following criteria Assumption there is 1 million dollars to be won and will be split as There are 3 tickets 6 numbers - wins jackpot, this could be shared amongst the 3 tickets 5 numbers-40% of the winning, if there was no jackpot, and can also be shared amongst winning tickets 4 numbers 20% of 1 million, if there was no jackpot, and can also be shared amongst winning tickets 3 numbers get a free ticket for next time lottery is played. You are required to share your pseudo code and critic and or under stand submissions, and why such approaches were taken Unread m ca Subscribe

Explanation / Answer


import java.util.*;

public class Lottery {
public static final int NUMBERS = 6;
public static final int MAX_NUMBER = 40;

public static void main(String[] args) {
// get winning number and ticket sets
Set<Integer> winningNumbers = createWinningNumbers();
Set<Integer> ticket = getTicket();
System.out.println();
  
// keep only the winning numbers from the user's ticket
Set<Integer> intersection = new TreeSet<Integer>(ticket);
intersection.retainAll(winningNumbers);
  
// print results
System.out.println("Your ticket numbers are " + ticket);
System.out.println("The winning numbers are " +
winningNumbers);
System.out.println();
System.out.println("You had " + intersection.size() +
" matching numbers.");
if (intersection.size() > 0) {
double prize = 100 * Math.pow(2, intersection.size());
System.out.println("The matched numbers are " +
intersection);
System.out.println("Your prize is $" + prize);
}
}
  
// generates a set of the winning lotto numbers
public static Set<Integer> createWinningNumbers() {
Set<Integer> winningNumbers = new TreeSet<Integer>();
Random r = new Random();
while (winningNumbers.size() < NUMBERS) {
int number = r.nextInt(MAX_NUMBER) + 1;
winningNumbers.add(number);
}
return winningNumbers;
}
  
// reads the player's lottery ticket from the console
public static Set<Integer> getTicket() {
Set<Integer> ticket = new TreeSet<Integer>();
Scanner console = new Scanner(System.in);
System.out.print("Type your " + NUMBERS +
" unique lotto numbers: ");
while (ticket.size() < NUMBERS) {
int number = console.nextInt();
ticket.add(number);
}
return ticket;
}
}