Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im having trouble outputing the question with the most lows scores. (That is a low score is 2 or lower). Suppose this URL contains the

Im having trouble outputing the question with the most lows scores. (That is a low score is 2 or lower).

Suppose this URL contains the result of 5 poll questions.

http://45.55.136.114/~dlash/java/scores.txt

Respondents rated questions from 1-5 where

1 -> meant they dis-liked the item

4 -> meant they like the item

Create a program that:

1.Reads this URL data,

2.counts the number of responses

3. calculates the average response per question

4. and shows the question with the most lows scores. (That is a low score is 2 or lower)

For example, your output may look like the following:

Q1 Q2 Q3 Q4 Q5

3.5 2.3 3.4 2.6 3.2

The total number of responses: 14

The question with the most ratings 2 or lower: Q2

---------------------------------------------------------------

Heres my program so far in java:

import java.io.IOException;

import java.net.URL;

import java.text.DecimalFormat;

import java.util.ArrayList;

import java.util.Map;

import java.util.Scanner;

import java.util.Set;

public class Question1 {

public static void main(String[] args) {

String URLString = "http://45.55.136.114/~dlash/java/scores.txt";

try {

java.net.URL url = new java.net.URL(URLString);

int count = 0;

Scanner input = new Scanner(url.openStream());

input.nextLine();

double q1 = 0;

double q2 = 0;

double q3 = 0;

double q4 = 0;

double q5 = 0;

while (input.hasNext()) {

String line = input.nextLine();

String toks[] = line.split(",");

double a = 0;

double b = 0;

double c = 0;

double d = 0;

double e = 0;

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

a = Double.parseDouble(toks[0]);

b = Double.parseDouble(toks[1]);

c = Double.parseDouble(toks[2]);

d = Double.parseDouble(toks[3]);

e = Double.parseDouble(toks[4]);

}

q1 += a;

q2 += b;

q3 += c;

q4 += d;

q5 += e;

count += toks.length;

}

int numQ = count / 5;

DecimalFormat numberFormat = new DecimalFormat("#.00");

System.out.println("Q1\t\tQ2\t\tQ3\t\tQ4\t\tQ5");

System.out.println(q1 + "\t\t" + q2 + "\t\t" + q3 + "\t\t" + q4 + "\t\t" + q5);

System.out.println("Q1Average\tQ2Average\tQ3Average\tQ4Average\tQ5Average");

System.out.print(numberFormat.format(q1 / numQ) + "\t\t" + numberFormat.format(q2 / numQ) + "\t\t"

+ numberFormat.format(q3 / numQ) + "\t\t" + numberFormat.format(q4 / numQ) + "\t\t"

+ numberFormat.format(q5 / numQ));

System.out.println(" The total number of responses: " + numQ);

System.out.println("The question with the most ratings 2 or lower: " + URLString);

} catch (java.net.MalformedURLException ex) {

System.out.println("Invalid URL");

} catch (java.io.IOException ex) {

System.out.println("IO Errors");

}

}

}

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

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago

Question

Describe the factors that lead to productive conflict

Answered: 1 week ago

Question

Understanding Conflict Conflict Triggers

Answered: 1 week ago