Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Arrays

  Asked By: Kerri    Date: Aug 21    Category: Java    Views: 461
  

I am trying to write a program that calculates the mean, median, and
standard deviation of a group of numbers. many numbers can be
entered at once in a text field bow, and i used a string tokenizer
to get the values. My problem is putting the data into an array. I
am trying to put the numbers in ascending numerical order, so that i
can easily find the median. the problem i am having is that my code
outputs the numbers, so i know they are going into the array, but
they are in exactly the same order as typed. here is my code.


in the first GUI class called "TestStats" is where I use the string
tokenizer. It works when the "enter data" button is pressed.


private void processButtonAction(String buttonText)
{

if (buttonText.equals("Enter Data"))
{
String strNumber = dataTextField.getText();

StringTokenizer retriever = new StringTokenizer(strNumber);
while (retriever.hasMoreTokens())
{
double num = Double.parseDouble(retriever.nextToken());
stats.addToStats(num);
}
dataTextField.setText("");
}
}


Then in the second class called "Statistics" my code for ordering
the numbers is:

public void addToStats(double num)
{

int numX = lastIndex;

while ((numX >= 0) && (list[numX]>num))
{

list[numX] = list[numX];
numX--;

list[numX+1] = num;
lastIndex++;
}
System.out.println(num);
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Arrays Or get search suggestion and latest updates.




Tagged: