Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a simple polling program that allows users to rate 5 issues from 1 (low importance) to 10 (high importance). Use a one dimensional array

Write a simple polling program that allows users to rate 5 issues from 1 (low importance) to 10 (high importance). Use a one dimensional array of type String to store the five causes. Prompt for the number to be polled. Use a 5X(numPolled) int array to store the results of the survey,

but please prompt for the file name. When you run the program ask a user rate each issue. The five issues are Environment, War and Peace, Economy, Education, and Infrastructure. Read in the five causes from a file Repeat this process for tnumPolled users. If a user gives an out of range keep prompting the user until the user answers the question correctly.

Write the following outputs to a file (prompt for the name). Include the following:

  1. A tabular report with 5 topics down the left side and the results of the ratings for the numPolled users on the line as shown in the text file.
  2. To the right of each row show the average of the results to two decimal places.
  3. Determine which issue received the highest poll total and write out that cause and its poll average.
  4. Determine which issue received the highest poll total and write out that cause and its poll average.

Implementation Guidance.

You should implement the above program with the following methods:

main

Create a String array of causes called causesList..

Calls readCauses with no parameters, which returns a reference to a String array.

Requests number (numPolled) to be polled interactively.

Call performSurvey with the causesList and numPolled as parameters. This method returns a reference to a two dimensional int array with the pollResults. (Can call it pollResults in main)

Call calcCausesSums with pollResults as a parameter. Return a reference to a one-dimensional int array with the sums by row.(Can call it causesSum in main

Call calcAverage with reference to causesSum and the value of numPolled as parameters, returning a reference to a one-dimensional double array. (Can call it averageForCause)

Call reportResults with causesList, pollResults, averageForCause, causesSum references as parameters, and no return value.

readCauses with no parameters

readCauses sets up a Scanner and reads from a file the causes. The file format is one cause per line. You can hardcode in the number of causes as 5 causes for this example. Return a reference to a String array with the causes. You can use my causes.txt file.

performSurvey with the causesList reference and numPolled as parameters

Interactively request the importance for each pollee. Put the answers into a two dimensional int array and return a reference to it. Reject and request a new value for any value less than 1 or greater than 10See below for the possible format for the interactive questioning.

calcCausesSums with pollResults reference as parameter

Calculate the total for each row (cause) and return results in a one-dimensional int array.

calcAverage with causesSum reference and the value of numPolled as parameters

Calculate the average for each row and return a reference to a one dimensional array.

reportResults with causesList, pollResults, averageForCause, causesSum references as parameters

Interactively request an output file name, and create an output File and use PrintWriter to write to it.

Produce the output similar to that in my pollresults.txt file. The average must be printed to two decimal places.

Call findMaxCause with a reference to average as a parameter, returning an int of the array index with the highest average or the first with that average if all are the same.

Call findMinCause with a reference to average as a parameter, returning an int of the array index with the lowest average or the first with that average if all are the same.

Write out the last two lines to your file as shown in the pollresults.txt file.

findMaxCause and findMinCause each accept a reference to average and return the index as described above.

Output:

Polling Results

Cause Polled Person Average

1 2 3 4

Environment 5 10 1 1 4.25

War and Peace 6 9 10 7 8.00

Economy 7 4 5 9 6.25

Education 8 7 8 3 6.50

Infrastructure 3 7 3 10 5.75

The cause War and Peace with an average rating of 8.00 is the highest rated cause

The cause Environment with an average rating of 4.25 is the lowest rated cause

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions