Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA QUESTION: Each program or class is to be submitted in a separate file with the file name being the class name with extension .java

JAVA QUESTION:

Each program or class is to be submitted in a separate file with the file name being the class name with extension .java as shown below. I only need the source file.

GeneralAverage.java

All solution will be posted on the web site after the due date.

  1. Polling

Write a simple polling program that allows users to rate 5 issues from 1 (low importance) to 10 (high importance). Read in the five causes from a file (you can use the causes.txt file under HOMEWORK & PROGRAMS 1 ANSWERS), but please prompt for the file name.. 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.

When you run the program ask a user rate each issue. 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). You can see a sample output in the pollresults.txt file. 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.

Sample interactive portion of program:

Please enter name of file to read causes from: causes.txt

Please enter number of users to be polled: 4

Pollee number 1

Please enter a value from 1 to 10, with 1 being lowest and 10 being highest importance for each case

Enter importance ranking for Environment: 5

Enter importance ranking for War and Peace: 6

Enter importance ranking for Economy: 7

Enter importance ranking for Education: 8

Enter importance ranking for Infrastructure: 3

Pollee number 2

Please enter a value from 1 to 10, with 1 being lowest and 10 being highest importance for each case

Enter importance ranking for Environment: 10

Enter importance ranking for War and Peace: 9

Enter importance ranking for Economy: 4

Enter importance ranking for Education: 7

Enter importance ranking for Infrastructure: 7

Pollee number 3

Please enter a value from 1 to 10, with 1 being lowest and 10 being highest importance for each case

Enter importance ranking for Environment: 1

Enter importance ranking for War and Peace: 10

Enter importance ranking for Economy: 5

Enter importance ranking for Education: 8

Enter importance ranking for Infrastructure: 3

Pollee number 4

Please enter a value from 1 to 10, with 1 being lowest and 10 being highest importance for each case

Enter importance ranking for Environment: 1

Enter importance ranking for War and Peace: 7

Enter importance ranking for Economy: 9

Enter importance ranking for Education: 3

Enter importance ranking for Infrastructure: 10

Please enter name of file to write poll results to: pollresults.txt

************* causes.txt ******************

Environment War and Peace Economy Education Infrastructure

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

Students also viewed these Databases questions

Question

Persuasive Speaking Organizing Patterns in Persuasive Speaking?

Answered: 1 week ago