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

ID: 3873088 • Letter: #

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 forstatement. 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

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

________________

PollingSports.java

import java.util.Scanner;

public class PollingSports {

// Declaring static variables

static Scanner sc= new Scanner(System.in);

static String sports[] = { "speed skating", "snowboard", "figure skating",

"bobsleigh", "ice hockey" };

public static void main(String[] args) {

// Getting how many persons you want to servey

System.out.print("Enter the number of responses :");

int noOfpeople = sc.nextInt();

// Creating an array

int ratings[][] = new int[sports.length][noOfpeople];

// calling the methods

ratings = compute(ratings, noOfpeople);

displayResults(ratings);

}

//This method will calculate the total and average

private static void displayResults(int[][] ratings) {

System.out.println("Statistics of the responses");

int tot = 0;

double avg = 0.0;

System.out.println(" 1 2 Average Total");

for (int i = 0; i < ratings.length; i++) {

System.out.print(sports[i] + " ");

for (int j = 0; j < ratings[0].length; j++) {

System.out.print(ratings[i][j] + " ");

tot += ratings[i][j];

}

avg=(double)tot / ratings[0].length;

System.out.print(avg+ " ");

System.out.print(tot + " ");

tot=0;

}

}

private static int[][] compute(int[][] ratings, int noOfpeople) {

for (int i = 0; i < ratings.length; i++) {

for (int j = 0; j < noOfpeople; j++) {

System.out.print("Enter response "+(j+1)+" for "+sports[i]+":");

ratings[i][j] = validRating();

}

}

return ratings;

}

/*

* This method will get the rating and check whether it is valid or not

*

* @Param void

*

* @return integer

*/

private static int validRating() {

int rate;

while (true) {

rate = sc.nextInt();

if (rate < 0 || rate > 10) {

System.out.println("** Must be between 1-10 **");

System.out.print("Enter again :");

continue;

} else

break;

}

return rate;

}

}

_____________________

Output:

Enter the number of responses :2

Enter response 1 for speed skating:9

Enter response 2 for speed skating:8

Enter response 1 for snowboard:3

Enter response 2 for snowboard:7

Enter response 1 for figure skating:10

Enter response 2 for figure skating:9

Enter response 1 for bobsleigh:5

Enter response 2 for bobsleigh:9

Enter response 1 for ice hockey:1

Enter response 2 for ice hockey:8

Statistics of the responses

1 2 Average Total

speed skating 9 8 8.5 17

snowboard 3 7 5.0 10

figure skating 10 9 9.5 19

bobsleigh 5 9 7.0 14

ice hockey 1 8 4.5 9


_____________Could you rate me well.Plz .Thank You