Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads 24 integer data from a data file, places the integer

ID: 3635148 • Letter: W

Question

Write a program that reads 24 integer data from a data file, places the integer values in a 20 array, and displays them. The first row of the data represents the high temp values for 12 months of the year and the second row represents the low temperature for the 12 months of the year. Your program must perform the calculations performed in the following spreadsheet. This requires that you write methods to perform max, min, avg, and standard deviation calculation for each data set. Data File: 35 42 49 52 70 75 85 95 98 55 40 30 2 15 20 22 30 50 60 70 75 50 30 25 Read-in temps and display them: 35 42 49 52 70 75 85 95 95 55 40 30 2 15 20 22 30 50 60 75 50 30 25 The avg high temp is: 60.50 The max high temp is :98 The avg low temp is :37.42 The min low temp is: 2 The high_temp std_dev is: 23.50

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class FileIn
{public static void main(String[] args)throws FileNotFoundException
{String filename;
Scanner kb=new Scanner (System.in);
System.out.print("Enter name of file with data ");
filename=kb.nextLine();
Scanner in=new Scanner(new File(filename));
int[][] temp=new int[2][12];
int i,j,sum,min,max;
double avgHigh,avgLow,sdd;
for(i=0;i<2;i++)
    for(j=0;j<12;j++)
        temp[i][j]=in.nextInt();
System.out.println("Data read");
for(i=0;i<2;i++)
    {for(j=0;j<12;j++)
         System.out.print(temp[i][j]+" ");
    System.out.println();
    }
avgHigh=getAverage(temp[0]);
System.out.printf("The avg high temp is %.2f ",avgHigh);
max=getMax(temp[0]);
System.out.println("The max high temp is "+max);
avgLow=getAverage(temp[1]);
System.out.printf("The avg low temp is %.2f ",avgLow);
min=getMin(temp[1]);
System.out.println("The min low temp is "+min);
System.out.printf("The high temp std dev is: %.2f ",sdd(temp[0],avgHigh));
}
public static double getAverage(int temp[])
{double a;
int i,sum=0;
for(i=0;i<12;i++)
     sum+=temp[i];
a=sum/12.;
return a;
}
public static int getMax(int temp[])
{int i,max=0;
for(i=1;i<12;i++)
     if(temp[i]>temp[max])            max=i;
return temp[max];
}
public static int getMin(int temp[])
{int i,max=0;
for(i=1;i<12;i++)
     if(temp[i]<temp[max])
            max=i;
return temp[max];
}
public static double sdd(int x[],double average)
{double variance=calcvariance( x,average);   
return Math.sqrt(variance);
}
public static double calc(int x,double avg)
{double temp;
temp=x-avg;
return temp*temp;
}

public static double calcvariance(int x[], double average)
{double mean, sum=0;
int i;
for(i=0;i<12;i++)
    sum+=calc(x[i],average);
mean=sum/12.;
return mean;
}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote