(Polling) The Internet and the web are enabling more people to network, join a c
ID: 3854595 • Letter: #
Question
(Polling) The Internet and the web are enabling more people to network, join a cause, voice opinions, and so on. The U.S. presidential candidates in 2008 used the Internet intensively to get out their messages and raise money for their campaigns. In this exercise, you’ll write a simple polling program that allows users to rate five social-consciousness issues from 1 (least important) to 10 (most important). Pick five causes that are important to you (e.g., political issues, global environmental issues). Use a one-dimensional array topics (of type char *) to store the five causes. To summarize the survey responses, use a 5-row, 10-column two-dimensional array responses (of type int), each row corresponding to an element in the topics array. When the program runs, it should ask the user to rate each issue. Have your friends and family respond to the survey. Then have the program display a summary of the results, including: a) A tabular report with the five topics down the left side and the 10 ratings across the top, listing in each column the number of ratings received for each topic. b) To the right of each row, show the average of the ratings for that issue. c) Which issue received the highest point total? Display both the issue and the point total. d) Which issue received the lowest point total? Display both the issue and the point total.
Explanation / Answer
Note: since Language is not mentioned .so I implemented program in Java.
//INCLUDE HEADER FILES
import java.io.*;
import java.util.*;
//CLASS
public class pollingIMP
{
//MAIN METHOD
public static void main(String[] args)
{
//SCANNER TO READ INPUT FROM THE USER
Scanner rateIn = new Scanner(System.in);
//STRING ARRAY TO HOLD 5 ISSUES
String[] socialIssue={"Pollution","Tsunami","Equal Rights","Developments in medical field ","Food Shortage"};
//GENERATE RANDOM
Random randNo = new Random();
int poll = randNo.nextInt(5) + 5;
//ARRAY OF 5ROWS AND 10 COLUMNS
int [][] POLLRATES= new int[5][10];
//GET RATING FROM THE USER FOR EACH ISSUE
for (int k1 = 0; k1 < poll; k1++)
{
System.out.println("Person #" + k1+1);
System.out.println("RATE THE FOLLOWING ISSUES FROM 1TO 10:");
for (int k2 = 0; k2 < socialIssue.length; k2++)
{
System.out.println(socialIssue[k2]);
POLLRATES[k2][k1] = rateIn.nextInt();
}
}
//CALCULATION PART
int minPollRating = 10;
int maxPollRating = 0;
int minPollRatingIndex = 0;
int maxPollRatingIndex = 0;
for (int k1 = 0; k1 < socialIssue.length; k1++)
{
System.out.print(socialIssue[k1]+":");
int totRating = 0;
for (int k2 = 0; k2 < poll; k2++)
{
System.out.print(" "+POLLRATES[k1][k2]);
totRating += POLLRATES[k2][k1];
}
//DISPLAY THE AVERAGE OF EACH ISSUE
double avgRate = ((double)totRating)/poll;
System.out.println(" Average ofRating: "+avgRate);
if (totRating < minPollRating )
{
minPollRating = totRating;
minPollRatingIndex = k1;
}
if (totRating > maxPollRating ){
maxPollRating = totRating;
maxPollRatingIndex = k1;
}
}
//DISPLAY MAXIMUM RATED ISSUE
System.out.println("Max points: "+socialIssue[maxPollRatingIndex]+": "+maxPollRating+" points");
//DISPLAY MINIMUM RATED ISSUE
System.out.println("Min points: "+socialIssue[minPollRatingIndex]+": "+minPollRating+" points");
System.out.println();
}//MAIN ENDS
}//CLASS ENDS
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.