I'm fairly new to Java and would greatly appreciate any help on this code! Arrays are my weak point, and to be honest, I've tried to figure this problem out but it's taking me a long time. Thank you!! :)
Here is my assignment:
Your instructor will provide you with a text file, (numbers.txt), containing a large (N <= 1000) number of integers. The integers range in value from 0 to 100. The text file has been created with one value on each line. Due to the potential for the sum of the numbers to be very large, you should use a long integer in your calculation to find the average.
The number of integers in the file is unknown.
Your program must find the average, standard deviation, and mode of the list of numbers. The mode is defined as the value(s) present with the highest frequency. Calculating the standard deviation consists of the following steps:
Find the average of the list of numbers.
Determine the difference of each number from the average, and square each difference. Sum all the differences.
Divide this sum by (the number of values - 1).
Take the square root of the above division result from step c.
Expand|Select|Wrap|Line Numbers
- import java.io.*;
- import java.util.*;
- /**
- * Class Statistics
- *
- *
- */
- public class Statistics
- {
- private double total;
- private double sum;
- int[] numbers = new int[1000];
- /**
- * This sets the total and sum to 0.
- */
- public Statistics()
- {
- }
- /**
- * This method finds the average of numbers listed in a txt file.
- */
- public void avg(int[] list)
- {
- for(int index = 0; index < list.length; index++)
- {
- System.out.print(list[index] + "");
- list[index] = list[index]/list.length;
- }
- }
- public void standardDeviation(int[] list)
- {
- }
- public void mode(int[] list)
- {
- FileInput in = new FileInput("numbers.txt");
- int num;
- while(inFile.hasMoreLines())
- {
- String line = inFile.readLine();
- for(int index2 = 0; index2 < line.length(); index++)
- {
- num = line.numAt(index2);
- }
- }
- num = '0';
- for(int loop = 0; loop < 1000; loop++)
- {
- System.out.println(num + ":" + numbers[loop]);
- num++;
- }
- }
- public static void main(String[] args)
- {
- final int max = 1000;
- Statistics stat = new Statistics();
- int[] file = new int[max];
- for(int loop = 0; loop < max; loop++)
- {
- file[loop] = loop;
- }
- stat.avg(file);
- stat.mode(file);
- }
- }