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

Your task is to write an application to ask people’s preferences on a topic of y

ID: 3871323 • Letter: Y

Question

Your task is to write an application to ask people’s preferences on a topic of your choice and compute statistics and display the results. Follow the direction in Exercise 7.40, but with your own topic, instead of surveying social-consciousness issues. An example topic is to survey the favorite winter Olympic games people want to watch among speed skating, snowboard, figure skating, bobsleigh, and ice hockey. Rate the item from 1 (least preferred) to 10 (most preferred). You must use at least one enhanced for statement. Please use a separate method to compute and display the results instead of implementing all the code in the main method. The method must have at least one parameter of an array that includes the user input.

Your code must compile and run from the windows command line using the following commands.

javac Polling.java

java Polling

You must add appropriate comments in you code as below and generate javadoc.

Add class level javadoc comment with @author tag and description about the class.

Add method level javadoc comments with @param and @return (if your method returns a

value) tags with the description of the method, parameters, and return value.

In the methods, please add end-of-line or block comments whenever necessary to help others

understand your code

DO NOT add comments such as “ // end of method”, “// end of class”. Such comments were

added in the textbook just teach you the Java grammar. Your application does not need to explain the Java grammar. Instead, you have to explain what your application does.

Please make sure the java documents you generated contains your javadoc comments properly.

Explanation / Answer

import java.util.*;

public class Polling

{

/**

* String array olympicGames[] to store Olympic game names

*/

static String olympicGames[] = {"Speed skating", "Snowboard", "Figure skating", "Bobsleigh", "Ice hockey"};

/**

* @param statistics[]

* Integer array contains statistics

* Displays statistics of people’s preferences

*/

static void displayStatistics(int statistics[])

{

System.out.println("************* Statistics of people’s preferences for Olympic games ***************");

System.out.println("Game Name " + " People Preference");

/*

* Loops up to number of statistics

*/

for(int counter = 0; counter < statistics.length; counter++)

{

System.out.println(olympicGames[counter] + " " + statistics[counter]);

}

}

/**

* @param statistics[]

* Integer array contains statistics

* Calculates statistics of people’s preferences

*/

static void calculateStatistics(int statistics[])

{

int pre;

Scanner sc = new Scanner(System.in);

System.out.print(" Enter number of persons in the pooling: ");

int numberOfPerson = sc.nextInt();

/*

* Loops up to number of persons

*/

for(int personC = 0; personC < numberOfPerson; personC++)

{

System.out.println("Olympic Game Events");

for(int counter = 0; counter < olympicGames.length; counter++)

{

System.out.println("Enter " + (counter + 1) + " for " + olympicGames[counter]);

}

System.out.print(" Enter your preference: ");

pre = sc.nextInt();

statistics[pre-1]++;

}

sc.close();

}

/**

* @param args

* for command line argument

*/

public static void main(String[] args)

{

/*

* preference[] to store user preference for the game

*/

int preference[] = new int[olympicGames.length];

calculateStatistics(preference);

displayStatistics(preference);

}

}

Sample Run:

Enter number of persons in the pooling: 10

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 1

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 2

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 4

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 1

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 5

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 1

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 2

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 3

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 1

Olympic Game Events

Enter 1 for Speed skating

Enter 2 for Snowboard

Enter 3 for Figure skating

Enter 4 for Bobsleigh

Enter 5 for Ice hockey

Enter your preference: 4

************* Statistics of people’s preferences for Olympic games ***************

Game Name People Preference

Speed skating 4

Snowboard 2

Figure skating 1

Bobsleigh 2

Ice hockey 1