# calculate mean,mode,median,range

Page 1 of 1

## 1 Replies - 18708 Views - Last Post: 10 April 2008 - 04:53 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=48760&amp;s=154357fb187ef84d83c12731d1fc496c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 k_tec

Reputation: 1
• Posts: 11
• Joined: 07-June 07

# calculate mean,mode,median,range

Posted 10 April 2008 - 04:41 PM

design an interface, read a set of values from a file, write methods to calculate the following:mean, mode, median, range.

```import java.io.*;
import java.math.*;
import java.util.Arrays;
public class NewStatJFrame extends javax.swing.JFrame {

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int numarr[]=new int[9000];
int count=0;
Mean Men = new Mean();
try {
DataInputStream in = new DataInputStream(new FileInputStream("c:\\tc\\num.txt"));

while (num != null){
numarr[count]=Integer.parseInt(num);
count++;
}
in.close();
jTextField1.setText(Men.mean(numarr, count-1));

} catch (Exception e) {System.out.println("Sorry, it cannot be done!");}

for (int i=0;i<=count-1;i++)
{System.out.println(numarr[i]);}
}

```

Is This A Good Question/Topic? 0

## Replies To: calculate mean,mode,median,range

### #2 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: calculate mean,mode,median,range

Posted 10 April 2008 - 04:53 PM

So what is your question ?
You have problem with the calculations or the GUI ?

Just a suggestion (not forced to follow it): start by a console application that will do all the calculations and print them with System.out.println() when that part works then you it will be time to start coding a nice display with Swing.

Divide to reign the Romans used to say.