7
« on: April 24, 2014, 02:16:26 PM »
I have a slow paced, badly taught computer science class in which we use "JCreator" as our JRE. The class is pretty easy despite being poorly taught, as all of the content was taken from another teacher from another school, and the teacher shows signs of not knowing what she's talking about, but that's not important.
I came to an area in the content that was written very peculiarly and i can't seem to understand it. What i need to do for an assignment is to find the mean, median, and mode of some arrays in order to display that I learned from the passage, which isn't making much sense. I don't really know where to start. I'll post the code by itself to give you some context on what i'm trying to find out. I'd appreciate it if any of you could help me with this. (I'm not asking you to do it, i'm really just trying to figure it out). What exactly does toString and fill do, and
is list[index] actually just an identifier/variable or is the "index" between brackets a reserved word?
import java.util.Arrays;
import java.util.Random;
public class TextLab06st
{
public static void main(String args[])
{
System.out.println("\nTextLab06\n");
System.out.print("Enter the quantity of random numbers ===>> ");
int listSize = Expo.enterInt();
System.out.println();
Statistics intList = new Statistics(listSize);
intList.randomize();
intList.computeMean();
intList.computeMedian();
intList.computeMode();
intList.displayStats();
System.out.println();
}
}
class Statistics
{
private int list[]; // the actual array of integers
private int size; // user-entered number of integers in the array
private double mean; // used for the 80, 100 and 110 point versions
private double median; // used for the 100 and 110 point versions
private int mode; // used for the 110 point version only
public Statistics(int s)
{
size = s;
list = new int[size];
mean = median = mode = 0;
}
public void randomize()
{
// This provided method creates the same exact list of "random" numbers for every execution.
// You will learn more about this in Chapter 14. For now just use the provided method.
Random rand = new Random(12345);
for (int k = 0; k < size; k++)
list[k] = rand.nextInt(31) + 1; // range of 1..31
}
public void computeMean()
{
}
public void computeMedian()
{
}
public void computeMode()
{
// precondition: The list array has exactly 1 mode.
}
public void displayStats()
{
System.out.println(Arrays.toString(list));
System.out.println();
System.out.println("Mean: " + mean);
System.out.println("Median: " + median);
System.out.println("Mode: " + mode);
}
}
(This is probably the wrong place for this thread, but I wasn't sure where else to put it. It was either this or mod discussion, but I don't remember if mod discussion was exclusively blockland or not. It's been a little while).