JAVA Programming Language
Question 1: Nested Loops:
You are organising a 21m birthday party for your best friend. At
the party, the DJ allows the guests to vote for their favourite
songs, and the last song of the party is the most popular song. The
DJ will give a list of five songs to ten random guests and ask them
to choose their favourite song. The song which receives the most
votes will be the most popular song. If there is more than one song
which receives the most votes, then any of the most popular songs
can be played as the final song of the night.
Write a program that will complete the following tasks:
1. Show each of the 10 users user a list of all
the five songs and ask them to choose their favourite.
2. Store the votes for the songs in an array,
where the first element of the array in the number of votes for the
first song, and so on.
3. Determine the most popular song.
4. Print out the most popular song and the number
of votes for the most popular song. If more than one song is voted
the most popular, then any of them may be printed out.
Please refer to screenshots
Code screenshot

Output

Code to copy
import java.util.Scanner;
public class DJ{
// array to hold songs name
public static String songs[] =
{"Song-1","Song-2","Song-3","Song-4","Song-5"};
// array to hohld votes
public static int votes[] = {0, 0, 0, 0, 0};
public static void main(String[] args){
Scanner sc = new
Scanner(System.in); // scanner class for input
for(int i = 0; i < 10;
i++){
// displaying
songs list to person i
for(int j = 0; j
< 5; j++){
System.out.println(String.valueOf(j + 1)+".
"+songs[j]);
}
System.out.println("Vote for Songs from person " + String.valueOf(i
+ 1));
int ch;
ch =
sc.nextInt(); // gettnig vote from person i
votes[ch - 1]++;
// updating votes
}
int most = 0;
// Determining most popular
song
for(int i = 0; i < 5;
i++){
if(votes[most]
< votes[i]){
most = i;
}
}
// Displaying most popular
song
System.out.println("Most Popular
Song is "+songs[most]);
}
}
JAVA Programming Language Question 1: Nested Loops: You are organising a 21m birthday party for your...