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

You are to write a program name powerball.java. You are to use arrays as your da

ID: 3662078 • Letter: Y

Question

You are to write a program name powerball.java. You are to use arrays as your data structure.
Here are some requirements for the program:
1. The program must prompt the user to enter the amount of groups of numbers he/she wants to
generate (must be between 1 and 5)
2. A group will be made up of two sets of numbers a
subgroup (set) of 5 numbers and another
subgroup (set) of 1 number.
3. The numbers must be randomly generated from the range of 1 69
for Sub Group 1 and 1 26
for Sub Group 2.
4. There must be no repetition of numbers in the same group.
5. However, if the user wants for example 2 groups, then it is possible for these two groups to differ
by only 1 number (so repetition between groups are allowed providing that the 2 groups are not
identical).
6. You are to use arrays to store the groups of numbers.
7. The program must also prompt the user asking him/her if he/she wants to buy more tickets. If
answer is "yes" rerun the program. If "no" terminate the program. If "yes" the random generator
must start back from time 0.
8. Sort the numbers in Group 1 in ascending order for each group.
9. Then display all of the tickets purchased by the user on the screen in the order of Group 1
followed by the single number in Group 2.

Explanation / Answer

Powerball.java

import java.util.HashSet;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

public class Powerball {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       System.out.println("Enter the number of set of groups to be generated");
       int numOfSets = scanner.nextInt();
       for (int i = 0; i < numOfSets; i++) {
           generateAndDisplayTickets();
       }  
       scanner.nextLine();
       System.out.println("Do you want to buy more tickets?");
       String response = scanner.nextLine();
       while (response.equals("yes")) {
           generateAndDisplayTickets();
           System.out.println("Do you want to buy more tickets?");
           response = scanner.nextLine();
       }
   }
  
   private static void generateAndDisplayTickets() {
       int[] group1 = new int[5];
       HashSet<Integer> hashSet = new HashSet<>();
       int group2, j = 0, temp;
       group2 = ThreadLocalRandom.current().nextInt(1, 27);
       while (true) {
           temp = ThreadLocalRandom.current().nextInt(1, 70);
           if (hashSet.contains(temp))
               continue;
           else {
               hashSet.add(temp);
               group1[j++] = temp;
           }
           if (j == 5)
               break;
       }
       for (int m = 0; m < 5; m++) {
           for (int n = 0; n < 4; n++) {
               if (group1[n] > group1[n+1]) {
                   temp = group1[n];
                   group1[n] = group1[n+1];
                   group1[n+1] = temp;
               }
           }
       }
       System.out.println("The tickets in Group 1 are:");
       for (int num: group1) {
           System.out.println(num);
       }
       System.out.println("The ticket in Group 2 is:");
       System.out.println(group2);
  
   }
}

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