473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Using Arrays to Find Mean, Mode, Standard Deviation

Hi All,

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
  1. import java.io.*;
  2. import java.util.*;
  3. /**
  4.  * Class Statistics
  5.  * 
  6.  * 
  7.  */
  8. public class Statistics
  9. {
  10.     private double total;
  11.     private double sum;
  12.  
  13.     int[] numbers = new int[1000];
  14.     /**
  15.      * This sets the total and sum to 0. 
  16.      */
  17.     public Statistics()
  18.     {
  19.  
  20.     }
  21.     /**
  22.      * This method finds the average of numbers listed in a txt file. 
  23.      */
  24.     public void avg(int[] list)
  25.     {
  26.         for(int index = 0; index < list.length; index++)
  27.         {
  28.             System.out.print(list[index] + "");
  29.             list[index] = list[index]/list.length;
  30.         }
  31.     }
  32.     public void standardDeviation(int[] list)
  33.     {
  34.  
  35.     }
  36.     public void mode(int[] list)
  37.     {
  38.         FileInput in = new FileInput("numbers.txt");
  39.         int num;
  40.         while(inFile.hasMoreLines())
  41.         {
  42.             String line = inFile.readLine();
  43.             for(int index2 = 0; index2 < line.length(); index++)
  44.             {
  45.                 num = line.numAt(index2);
  46.             }
  47.         }
  48.         num = '0';
  49.         for(int loop = 0; loop < 1000; loop++)
  50.         {
  51.             System.out.println(num + ":" + numbers[loop]);
  52.             num++;
  53.         }
  54.     }
  55.     public static void main(String[] args)
  56.     {
  57.         final int max = 1000;
  58.         Statistics stat = new Statistics();
  59.         int[] file = new int[max];
  60.         for(int loop = 0; loop < max; loop++)
  61.         {
  62.             file[loop] = loop;
  63.         }
  64.         stat.avg(file);
  65.         stat.mode(file);
  66.     }
  67.  
  68. }
  69.  
Dec 17 '14 #1
0 1751

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: T.Venkatesh | last post by:
Hi friends, I just got stuck up in JDBC,JSP. My problem is iam unable to display the output of Standard deviation , variance sum, of a column in a JSP page. But it complies- but no display of...
3
by: mat | last post by:
Je l'ai cherché partout, je ne l'ai pas trouvé, alors je l'ai écrite. Si ça peut servir à d'autres ... echo "Calcul d'un ecart type"; echo "<br>"; $datas =...
3
by: Scott | last post by:
I know in some other languages there is a simple standard deviation function (sdev(1,2,3,4,5,etc...)). But I'm unable to find a suitable alternative for vb.net I'm assuming it's there...
10
by: Verbal Kint | last post by:
DEAR ALL, I just have a very short question. In the FAQ list question 13.20 the following text is mentioned: "These methods all generate numbers with mean 0 and standard deviation 1. (To adjust...
4
by: attackwarningred | last post by:
Dear All, Hello! I've just started to use Python and its a lovely language! I've previously programmed in Fortran 95 and have just began to use numpy. I'm having a few problems with arrays in...
6
by: shibujohn82 | last post by:
Hi, My data set is followed like this... (as tab delimited input.csv) First is column is gene name, second column is bn count, third colums is sh count. ENSRNOG00000000417 42 102...
3
by: yawsam | last post by:
How can i use aggregate function like count, sum and other to calculate standard deviation in SQL
0
by: Dave Smith | last post by:
I’m hoping someone can help me with my newest rank issue. I’m trying to get a rank my standard deviation so it will be a number below 1, the numbers I'm trying to rank are below. Example: ...
6
by: crumble113 | last post by:
Can anyone please tell me where I am going wrong with this for loop which is meant to take as input a specific corpus, sample size and number of samples and then give the averages of the expected...
2
by: cemma | last post by:
Hello! So i am a new programmer and i really need some help. I am trying to find the Population Standard Deviation of 7 numbers which the user inputs. Please see below my double...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.