Question

In: Computer Science

This program is to be written in Java Language. Thank you A College has conducted a...

This program is to be written in Java Language. Thank you

A College has conducted a student survey. Students were asked to rate their satisfaction with remote learning courses. Students rated their satisfaction on a scale of 1 to 5 (1 = "I hate it", 5 = "I love it"). The student responses have been recorded in a file called "StudentResponses.txt". Each line of the file contains one student response.

Program 1 You are to write a program that reads and analyzes the survey responses. Your program should read the contents of the file and place the responses into an ArrayList. Your program should write a report to a file. The file should contain the number of students who responded to the survey, along with the mean, median, and standard deviation of the responses.

Program 2 Read the file "StudentResponses.txt" and count the number of occurances of the integers from 1 to 5. Use these counters to calculate the mean, median, and standard deviation.

Your program should use functions to calculate the mean, median and standard deviation. Each function should have an ArrayList as a parameter, and should return a double. Each function including the main should have a clearly stated algorithm.

Solutions

Expert Solution

Short Summary:

Implemented the program as per requirement

Attached source code and sample output

**************Please do upvote to appreciate our time. Thank you!******************

Source Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

//This class reads a file and calculates mean,median and standard deviation

public class StudentsSurvey {

   //Main function
   public static void main(String[] args) {

       //Declare array of size as per requirement
       int[] initialArray=new int[200];
       try {
           //Read file using scanner
           Scanner sc=new Scanner(new File("C:\\Users\\asus\\StudentResponses.txt"));
           int i=0;

           while(sc.hasNext())
           {
               initialArray[i]=sc.nextInt();
               i++;
           }
           int arrayLength=i;
           //Create an array with number of elements size
           int[] array=new int[arrayLength];
           for(int j=0;j<arrayLength;j++)
               array[j]=initialArray[j];
           sc.close();
           //Write to a file
           FileWriter obj=new FileWriter(new File("C:\\Users\\asus\\StudentResponseStatistics.txt"));

           obj.write("No Of students responded to the survey:"+arrayLength+"\n");
           System.out.println("No Of students responded to the survey:"+arrayLength);
           //Mean
           obj.write("Mean:"+String.valueOf(mean(array))+"\n");
           //Median
           obj.write("Median:"+String.valueOf(median(array))+"\n");
           //Standard Deviation
           obj.write("Standard Deviation:"+String.valueOf(standardDeviation(array))+"\n");
           obj.flush();
           obj.close();
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

   }
   //This method calculates mean of given array
   private static double mean(int[] array)
   {
       double mean;
       int sum, i;
       int n = array.length;
       sum = 0;
       //Calculate sum
       for(i = 0; i < n; i++) {
           sum+=array[i];
       }
       mean=(double)sum/n;

       return mean;

   }
   //This method calculates median of given array
   private static double median(int[] array)
   {
       int n = array.length;

       // sort the array
       Arrays.sort(array);
       if (n % 2 != 0)
           return (double)array[n / 2]; // even case

       return (double)(array[(n - 1) / 2] + array[n / 2]) / 2.0;
   }
   //This method calculates standardDeviation of given array
   private static double standardDeviation(int[] array)
   {
       double sum = 0.0, standardDeviation = 0.0;
       int n = array.length;

       //Calculate sum
       for(double num : array) {
           sum += num;
       }

       double mean = sum/n;

       for(double num: array) {
           standardDeviation += Math.pow(num - mean, 2);
       }

       return Math.sqrt(standardDeviation/n);

   }

}

Code Screenshot:


Output:

IP File:

OP File:

**************Please do upvote to appreciate our time. Thank you!******************


Related Solutions

This program should be written in Java language. Given the uncertainty surrounding the outbreak of the...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis. You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working...
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
Language: Java Create a TryIt.java program with a main method. You are going to use this...
Language: Java Create a TryIt.java program with a main method. You are going to use this program to demonstrate some things about how Java works. Make your methods here private, because they are not intended to be called from outside the program. For each test below, make sure that you print to the console: 1) What is being tested 2) The desired output 3) The actual output Question to be answered: Should you use == or the String method equals...
In this question, you are asked to write a simple java program to understand natural language....
In this question, you are asked to write a simple java program to understand natural language. The user will enter the input following the format: Name came to City, Country in Year. For example: Robin came to Montreal, Canada in 2009. Assume a perfect user will follow the exactly above formats for the inputs. Your program should be able to analyze the key words (Name, City, Country and Year) from the inputs and reorganize the outputs following format: Name stay...
You have written a JAVA program that creates Shoe object with three instance variables. You will...
You have written a JAVA program that creates Shoe object with three instance variables. You will need to use the exception you created to go along with it. So far you have been using my driver classes. Now it is time for you to create your own driver class that will implement an ArrayList of Shoe objects. This assignment uses the Shoe.java and ShoeException.java to create the driver ShoeStore.Java You will display a menu as follows: Add shoes Print all...
**Please write in Java, in a very simple/beginner coding style/language - thank you!** Directions: Given a...
**Please write in Java, in a very simple/beginner coding style/language - thank you!** Directions: Given a factorial n!. Find the sum of its digits, and the number of trailing zeros (ie: the number of zeros at the end of the factorial). Input: integer nn, a non-negative integer where n≤20n≤20 Output: integer xyxy, the concatenation of x and y, where x is the sum of the digits in n! and y is the number of the zeros in n!) Note, 0≤x,y0≤x,y....
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT