I need help with this Java program: Write a java program “Running a lottery for
ID: 3594468 • Letter: I
Question
I need help with this Java program:
Write a java program “Running a lottery for migacents”, with a price of $4000.00:
· Start with an empty bag.
· Each ticket is represented by an integer, with its range being determined by the programmer.
· One ticket number may be purchased multiple times.
· For each ticket purchased, put an item in the bag.
· Don't grab if not tickets purchased.
· The odds should be determined before the sale.
The winning number should be randomly picked up in the number range announced before the sale.
· Use a special number (e.g. –1) as the indication of the end of the sales.
· The winner’s number should be announced, as well as the number of winners, and the price for each winner. If there is no winner, an announcement, which include the message “the price will be roll over to next round”, should also be made.
Explanation / Answer
package newpackage;
import java.util.Random;
import java.util.Scanner;
public class Lottery {
public static void main(String[] args) {
int maxNumber;
int count=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the range of the ticket number");
maxNumber=sc.nextInt();
System.out.println("Enter the number of participants for lottery");
int totalMembers=sc.nextInt();
int arr[]=new int[totalMembers];
for(int i=0;i<totalMembers;i++)
{
System.out.println("Enter the lottry number you want to buy the range is form 1 to "+maxNumber);
arr[i]=sc.nextInt();
}
Random rand=new Random();
int lotteryNumber=rand.nextInt(maxNumber);
lotteryNumber=lotteryNumber+1;
System.out.println("This round lottery number is "+lotteryNumber);
for(int i=0;i<totalMembers;i++)
{
if(lotteryNumber==arr[i])
{
count++;
}
}
if(count==0)
{
System.out.println("The price will be rolled over to next round");
}
else {
System.out.println("Then number of lottery winners are "+count);
System.out.println("Price money for each lottery memeber is $"+4000/count);
}
}
}