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

Write a program in java LotteryPrinter that picks a combination in a lottery. In

ID: 3781988 • Letter: W

Question

Write a program in java LotteryPrinter that picks a combination in a lottery. In this lottery, a lottery ticket consists of 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.

Explanation / Answer

Solution:

import java.util.Random;

public class LotteryPrinter {
  
public static void main(String[] args){
String res;
res = “Play this combination – it’ll make you rich ";
res += String.format("%d , %d ", pickNumber(),pickNumber());
res += String.format("%d , %d ", pickNumber(),pickNumber());
res += "*Results not gauranteed";
return res;
}
  
  
public static int pickNumber(){
Random lottorynum;
lottorynum = new Random();
int num = lottorynum.nextInt(48) + 1;
return num;
}
}

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