5.4 Java Create a program that generates SuperLotto lottery numbers.
Example output:
How many Super Lotto tickets do you want?
4
28 8 11 9 28 MEGA (4)
38 39 29 47 27 MEGA (27)
15 17 33 12 6 MEGA (19)
30 29 18 20 31 MEGA (12)
import java.util.Random;
import java.util.Scanner;
class SuperLottoPlus {
public static int[] generateSuperLottoNumbers()
{
int arr[] = new int[6];
Random r = new Random();
for (int i = 0; i < 5;
i++)
arr[i] =
r.nextInt(47) + 1;
arr[5] = r.nextInt(27) + 1;
return arr;
}
public static void printTicket(int arr[]) {
for (int i = 0; i < 5;
i++)
System.out.print(arr[i] + " ");
System.out.println("(MEGA: " +
arr[5] + ")");
}
public static int[] generateSuperLottoNoDupes()
{
int arr[] = new int[6];
int count[] = new int[47];
int n = 0;
Random r = new Random();
for (int i = 0; i < 5;) {
n =
r.nextInt(47) + 1;
if (count[n] ==
0) {
arr[i] = n;
count[n]++;
i++;
}
}
arr[5] = r.nextInt(27) + 1;
return arr;
}
}
public class SuperLottoPlusDemo {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.println("How many Super
Lotto tickets do you want?");
int n = sc.nextInt();
for (int i = 0; i < n;
i++)
SuperLottoPlus.printTicket(SuperLottoPlus.generateSuperLottoNumbers());
System.out.println("How many Super
Lotto tickets do you want without dup?");
n = sc.nextInt();
for (int i = 0; i < n;
i++)
SuperLottoPlus.printTicket(SuperLottoPlus.generateSuperLottoNoDupes());
}
}
5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create...
Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements: The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...
Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...
Create a class called Play that has an InputReader as an instance variable. Be sure to initialize it in the constructor. The class has two methods. Write a method with this signature: Write a method with this signature: public void stringPlay() The method prompts the user for a string, reads it in, and then displays the string as many times as the length of that string. The output string should be formatted with the first letter uppercase and the rest...
Write a Lottery class that simulates a 6-number lottery (e.g. "Lotto"). The class should have an array of six integers named lotteryNumbers, and another array of six integers named userLotteryPicks. The class' constructor should use the Random class to generate a unique random number in the range of 1 to 60 for each of the 6 elements in the lotteryNumbers array. Thus, there should be a loop that keeps generating random numbers until all 6 numbers are unique. The Lottery class...
java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. 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: Select 7...
Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...
Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...
in java eclipse, Create a program “FibonacciFifteen.java” and a method called “double[] getFibonacci()” that creates an array with a length of 15 that contains the first 15 numbers in the Fibonacci sequence and returns it. Set the first element to 0 and the second element to 1, then use a for loop to fill out the rest of the array by adding the prior two elements.
Create a new class called DemoSortingPerformacne Create a private method called getRandomNumberArray. It returns an array of Integer and has 2 parameters: arraySize of type int and numberOfDigits of type int. This method should create an array of the specified size that is filled with random numbers. Each random numbers should have the same number of digits as specified in the second parameter In your main method (or additional private methods) do the following: Execute selection sort on quick sort...
Write a Java program that has a method called arrayAverage that accepts an arrary of numbers as an argument and returns the average of the numbers in that array. Create an array to test the code with and call the method from main to print the average to the screen. The array size will be from a user's input (use Scanner). - array size = int - avergage, temperature = double - only method is arrayAverage Output: