ok I am attempting to write a function that takes the set of integers in an arraylist and calculates the mode(s) from it. I can figure out what to do to find just one mode, however I need to find all the modes. I also cannot use normal arrays to calculate the mode. I have written the other functions of my statistics library just fine so far.
import java.util.*;
import java.io.*;
public class Stat
{
private ArrayList <Integer> list = new ArrayList <Integer> ();
public Stat()
{
try
{
Scanner in = new Scanner(new File("numbers.txt"));
ArrayList <Integer> unsortedList = new ArrayList <Integer> ();
while(in.hasNext())
{
list.add(in.nextInt());
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public double median()
{
double temp = 0;
for(int i=0; i < list.size(); i++)
temp += list.get(i);
temp /= list.size();
return temp;
}
public double Stand()
{
double temp = 0;
double median = median();
for(int i=0; i < list.size(); i++)
temp += Math.pow(list.get(i) - median ,2);
temp /= (list.size() - 1);
temp = Math.sqrt(temp);
return temp;
}
public ArrayList mode()
{
ArrayList <Integer> most=new ArrayList <Integer> ();
return most;
}
}
Actual code is not needed...just some psuedocode of some kind should help. Thank you.
Edited by: jrbabb on Dec 5, 2007 9:44 PM