Here is the solution if you have any doubts then you can write in the comment section.
Please give feedback.
Solution:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
//try catch block to handle exceptions
try
{
//open a new file named input.csv
File myObj = new File("input.csv");
//create Scanner Object
Scanner myReader = new Scanner(myObj);
//read 1st line, we want to skip this because it contain field name
myReader.nextLine();
//varibles
double value,sum=0,count=0,min=999999999,max=0;
//ArrayList to store values for finding std
ArrayList <Double> al=new ArrayList <Double>();
//read from file until line is present
while (myReader.hasNextLine())
{
// read line and store in data
String data = myReader.nextLine();
//split string by ,
String arr[]=data.split(",");
//value is 2nd element of array according to input given in question
value=Double.parseDouble(arr[1]);
//add value to ArrayList
al.add(value);
//add value to sum
sum+=value;
//increment count
count++;
//calculate max
if(value>max)
{
max=value;
}
//calculate min
else if(value<min)
{
min=value;
}
}
//calculate mean
double mean=sum/count;
double std=0.0;
//loop through all values
for(double values:al)
{
//calculate std
std+=Math.pow((values-mean),2);
}
//calculate sample std, please be sure that n>1
std/=(count-1);
//print values
System.out.println("Min: "+min);
System.out.println("Max: "+max);
System.out.println("Mean: "+mean);
System.out.println("Std: "+std);
//close file
myReader.close();
}
catch (FileNotFoundException e)
{
System.out.println("An error occurred.");
e.printStackTrace();
}
catch (ArithmeticException Ae)
{
System.out.println("Count should be greater than 1 for std");
}
}
}
Input/Output:
input.csv
date,price,region
2015-07-19,1.08,Louisville
2015-08-16,1.05,RichmondNorfolk
2015-04-05,1.1,Orlando
2015-07-26,1.12,GrandRapids
2015-05-31,1.1,Atlanta
output:
Thank You!
java Challenge Avocado Prices Programming challenge description: Consider a dataset containing the distribution of avocado prices...
Netflix stock prices have climbed since it was first introduced in 2002. A stock broker is interested in estimating the mean opening price for one share of Netflix stock. To do this, a random sample of 51 days from 2014 was taken, and the opening price of one share of the stock was recorded. The sample data is summarized in the StatCrunch output: Summary statistics: Column Mean Std. dev. Median Range Min Max Q1 Q3 Opening Price 51 409.6449 49.881232...
Hypothesis Testing Challenge #2-Discussion Board Group 3 Is there a significant difference between the mean age of people surveyed at the Home Show and the mean age of people surveyed at Pybus Market? From My on-campus statistics classes have been conducting surveys for Pybus Market in Wenatchee. The Fall 2014 surveyed customers at Pybus Market to learn more about customer demographics and inform marketing and funding strategies. The Winter 2015 class surveyed people at the Home Show to learn how...
Please help with the following, I have already done most of them. Please verify Question1 Select one answer The histogram below displays the distribution of so ages at death due to trauma (unnatural accidents and homicides) that were observed in a certain hospital during a week. opoints 18 16 14 12 10 а» 10 20 30 40 50 60 70 80 90 Age Which of the following are the appropriate numerical measures to describe the center and spread of the...
Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...