473,473 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Arrays to Find Mean, Mode, Standard Deviation

1 New Member
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 1760

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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.