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

Write a program SelectWinner.java to pick winners. You have 4 t-shirts and 2 ipa

ID: 3802333 • Letter: W

Question

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. (Make use of loops in your program). 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. Sample output: Winners for T-shirts are: Student number 7 9 12 9 Winners for i-Pads are: Student number 5 12 Write a program Days.java that performs the following Define a method called getDays which takes three integer parameters, month, day and year of a date, calculate and return the day number (total number of days since Jan 1^st) of the year. (Should consider leap year, make use of loops and do not use built-in Calendar class) Take user input of month, day and year of a date, call getDays method to print the date with full month name and day number of the year. See sample output. Sample output1: Enter month: 2 Enter day: 1 Enter year: 2017 February 1, 2017 is day 32 of 2017. Sample output2: Enter month: 3 Enter day: 2 Enter year: 2016 March 2, 2016 is day 62 of 2016

Explanation / Answer

Program 1.


import java.util.Random; // to generate random value
public class SelectWinner {
public static void main(String args[])
{
int rand_value;
System.out.print("Winners for T-Shirts are: Student Number");
for (int i=0;i<4;i++)
{
rand_value=(int)(Math.random()*17)+1; // Generate 4 random value in between 1 and 16
System.out.print(" "+rand_value);
}
System.out.println("");
System.out.print("Winners for i-Pads are: Student Number");
int rand1=(int)(Math.random()*17)+1; // Random 1 for 1st student
int rand2=(int)(Math.random()*17)+1; // Random 2 for 2nd student
for (int i=0;i<1;)
{
if(rand1==rand2) // Check if both are same then generate another random number
{
rand2=(int)(Math.random()*17)+1;
}
else
{
System.out.print(" "+rand1+" "+rand2);
i++;
}
}
System.out.println("");
  
}
}

Output:-

run:
Winners for T-Shirts are: Student Number 3 1 4 4
Winners for i-Pads are: Student Number 13 14
BUILD SUCCESSFUL (total time: 0 seconds)

Program 2:

import java.util.Scanner;
public class Days {
int day_no=0;
public void getDays(int month,int day,int year)
{
day_no=day_no+day; // Add Days in total days
for(int month_value=1;month_value<month;month_value++) // Loop for month days calculations
{
if(month_value==1 || month_value==3 || month_value==5 || month_value==7 || month_value==8 || month_value==10 || month_value==12 )
{
day_no=day_no+31; // if month have 31 days
}
if(month_value==4 || month_value==6 || month_value==9 || month_value==11 )
{
day_no=day_no+31; // if month have 30 days
}
if(month_value==2)
{
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
day_no=day_no+29; // if month Feb have 29 days and Leap year
else
day_no=day_no+28; // if month Feb have 28 days and not a Leap year
}
}
String month_name="";
// Convert Month Number into Month Name
switch(month)
{
case 1:
month_name="January";
break;
case 2:
month_name="February";
break;
case 3:
month_name="March";
break;
case 4:
month_name="April";
break;
case 5:
month_name="May";
break;
case 6:
month_name="June";
break;
case 7:
month_name="July";
break;
case 8:
month_name="August";
break;
case 9:
month_name="September";
break;
case 10:
month_name="October";
break;
case 11:
month_name="November";
break;
case 12:
month_name="December";
break;
}
System.out.println(""+month_name+" "+day+", "+year+" is day "+day_no+" of "+year);
}
public static void main(String args[])
{
int day,month,year;
Scanner Sc=new Scanner(System.in); // Take Console Input
System.out.println("Enter the Month: ");
month=Sc.nextInt(); // Input for Month
System.out.println("Enter the Day: ");
day=Sc.nextInt(); // Input for Day
System.out.println("Enter the Year: ");
year=Sc.nextInt(); // Input for Year
Days d1=new Days();
d1.getDays(month,day,year);
}
}

Output:-

run:
Enter the Month:
3
Enter the Day:
2
Enter the Year:
2016
March 2, 2016 is day 62 of 2016
BUILD SUCCESSFUL (total time: 3 seconds)

run:
Enter the Month:
2
Enter the Day:
1
Enter the Year:
2017
February 1, 2017 is day 32 of 2017
BUILD SUCCESSFUL (total time: 8 seconds)

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