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

Write a Java program Write a program LotteryPrinter that picks a combination in

ID: 3663960 • Letter: W

Question

Write a Java program Write a program LotteryPrinter that picks a combination in a lottery. In this lottery, players can choose 6 numbers (with none repeating) between 1 and 49. Construct an object of the Random class and invoke an appropriate method to generate each number. The numbers should be stored in an array and you must include some kind of logic to ensure that no two numbers are the same. Your program should print out a sentence such as “Play this combination—it’ll make you rich!” followed by a lottery combination. Write a Java program Write a program LotteryPrinter that picks a combination in a lottery. In this lottery, players can choose 6 numbers (with none repeating) between 1 and 49. Construct an object of the Random class and invoke an appropriate method to generate each number. The numbers should be stored in an array and you must include some kind of logic to ensure that no two numbers are the same. Your program should print out a sentence such as “Play this combination—it’ll make you rich!” followed by a lottery combination. Write a Java program

Explanation / Answer

Programm 1:
/* Java program for Lottery print */

import java.util.ArrayList; // Importing classes from Util Package
import java.util.Random;// Importing classes from Util Package
public class Loto {
        public static void main(String[] arg) {
        ArrayList<Integer> al1 = new ArrayList<Integer>(); //Initialising an Array
        for(int i11 = 1; i11 <= 49; i11++) // using for loop
                al1.add(i11);
            Random rand = new Random();
                    for(int i11 = 0; i11 < 6; i11++) {
                int x1 = al1.remove(rand.nextInt(al1.size())); //Initialise the value x1
                System.out.print(" " + x1); // printing the x1 values
            }
            System.out.println();
        }
   }
Programm 2:
/ * Java Program for Lottery Print * /

import java.util.*; //Importing all classes from Util Package

public class LotteryPrinter
{

public static void main(String args[])
{
   Menu(); //The Calling Menu() method
}

public static void Menu()
{
System.out.println("Choose the Lottery Numbers - 1. Choose any 6 Numbers between 1 to 49 2. The Number can be chosen more then once Enter Your random Numbers - ");
int LotNum[] = new int[6]; //Initalising an Array with name LotNum
Scanner LotObj = new Scanner(System.in); //Making Object the LotObj
for(int i11=0;i11<=5;i11++)
   {
   LotNum[i11] = LotObj.nextInt(); //Taking the input from user
   if(LotNum[i11]>49||LotNum[i11]<=0) //The Checking if the Lotnum. is in between 1 & 49
    {
    System.out.println("Numbers are Entered should be between 1 & 49");
    Call(); // The Calling yourCall() method
    }
   }
Random RandObj = new Random(); //Creating an object of Random Class
int RandNum[] = new int[6]; // Initailising the RandNum[] array
System.out.println(" ----------------------- Lottery Numbers Are ----------------------");
System.out.println("********************************************************");
for(int i11=0;i11<=5;i11++)
   {
   RandNum[i11] = RandObj.nextInt(49) + 1; //Generating the Random Numbers Betwwen 1 & 49
   System.out.print(" " + RandNum[i11]);
   }
System.out.println(" ********************************************************");
int cntr = 0;
for(int j11=0;j11<=5;j11++) //Checking if Combination of Lottery Number Generated matches the entered Number
   {
   if(RandNum[j11] == LotNum[j11])
    {
    cntr = cntr + 1; //if LotNum matches RandNum increasing counter by 1
    }
   }
if(cntr == 6)
   {
   System.out.println(" ----------- YOU WON THIS LOTTERY -----------"); // if cntr = 6 printing YOU WON
   Call();
   }
else
   {
   System.out.println(" ----------- Try Again Later -----------");
   Call();
   }
}
public static void Call()
{
System.out.print("-------------------------- Do you want to play the again? Press 1 for Yes Press 2 to exit Enter your choice : ");
Scanner choi = new Scanner(System.in); // choice initialization
int ch = choi.nextInt();
switch(ch) //Switch statement is used for various purposes
   {
case 1:
   Menu();
   break;
case 2:
   bye();
   break;
default:
   System.out.println("Invalid Choice");
   break;
   }
}
public static void bye() //The Bye method is used for exit the program
{
System.out.println("--------------------------------------- Thank You For Using Lottery Machine Program ---------------------------------------");
System.exit(0);
}
}

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