This is a programming assignment for Java. Can I please get some help. Write a p
ID: 3857116 • Letter: T
Question
This is a programming assignment for Java. Can I please get some help.
Write a program SelectWinner.java to pick winners. You have 4 t-shirts and 2 ipads to give away and a pool of 16 students. The students are assigned numbers from 1 to 16. a. Randomly select 4 students to receive the t-shirts. (It is OK to select the same student more than one time) b. Randomly select 2 students to receive the iPads. Make sure to pick two different students. (Make use of loops in your program) Sample output: Winners for T-shirts are: Student number 7 9 12 9 Winners for i-Pads are: Student number 5 12Explanation / Answer
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.util.Random;
/* Name of the class has to be "Main" only if the class is public. */
class SelectWinner
{
public static void main (String[] args) throws java.lang.Exception
{ // your code goes here
Scanner in = new Scanner(System.in); //scanner toread inputs
Random rand = new Random(); // instantiate randaom
int N1=0;int looper=0;
while (looper<2) //looping for ipad
{
int n = rand.nextInt(16) + 1;
if (looper==0)
{ N1=n;
System.out.println(" Ipad winner is Student"+n+" "); // Display result
looper = looper +1;
}
if((looper ==1) && !(N1 == n)) // check for no repeatation
{
System.out.println(" Ipad winner is Student"+n+" "); // Display result
looper = looper +1;
}
}
int looper2=0;
while (looper2<4) //looping for t-shirt
{
int n = rand.nextInt(16) + 1;
System.out.println(" T-shirt winner is Student"+n+" "); // Display result
looper2 = looper2 +1;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.