calculate mean,mode,median,range

read numbers from a file and then do the calculations

Page 1 of 1

1 Replies - 16030 Views - Last Post: 10 April 2008 - 04:53 PM Rate Topic: -----

#1 k_tec  Icon User is offline

  • New D.I.C Head

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

calculate mean,mode,median,range

Post icon  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"));
			String num = in.readLine();
			
			while (num != null){
				numarr[count]=Integer.parseInt(num);
				num = in.readLine();
				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  Icon User is offline

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

Reputation: 8346
  • View blog
  • Posts: 31,908
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1