//at least try to figure out how it works
import java.util.Arrays;
public class Lab12
{
public static void main(String args[])
{
System.out.println("\nLAB12 AWESOME VERSION\n");
System.out.print("Enter the quantity of random numbers ===>> ");
int listSize = Expo.enterInt();
Statistics intList = new Statistics(listSize);
intList.randomize();
intList.computeMean();
intList.computeMedian();
intList.computeMode();
intList.displayStats();
}
}
class Statistics
{
private int list[];
private int size;
private double mean;
private double median;
private int mode;
private int count = 0;
private int count1;
private int value2;
public Statistics(int s)
{
list = new int[s];
size = s;
}
public void randomize()
{
Expo.startSeed(12345);
for(int k = 0; k < size; k++)
{
int rndNumber = Expo.seedRandom(10,20);
list[k] = rndNumber;
}
}
public void computeMean()
{
mean = 0;
for(int k = 0; k < size; k++)
{
mean += list[k];
}
mean = mean / size;
}
public void computeMedian()
{
Arrays.sort(list);
if (size%2 == 1)
{
median = list[((size / 2))];
}
else
{
int r = list[(size / 2)] + list[((size / 2) + 1)];
median = r / 2;
}
}
public void computeMode()
{
for(int k = 0; k + 1 < size - 1; k++)
{
int value1 = list[(k)];
if(k >= size)
{
mode = list[k];
count1 = count;
}
if(k+1 <= size)
{
value2 = list[(k+1)];
if(value1 == value2)
{
count += 1;
}
else
{
if(count > count1)
{
mode = value1;
count1 = count;
count = 0;
}
else
{
count = 0;
}
}
}
}
}
public void displayStats()
{
System.out.println();
System.out.println();
System.out.println(Arrays.toString(list));
System.out.println("Mean: " + mean);
System.out.println("Median: " + median);
System.out.println("Mode: " + mode);
}
}
my code for java class, it's probably stupid. play with it so you figure out how it works. it's been put on here as a purely "collaborative" learning effort
Wednesday, February 16, 2011
Tuesday, February 15, 2011
Code
//this code will have no purpose. whatsoever
public class JavaPractice001
{
public static void main(String args[])
{
int a = 25;
int b = 10;
int c = 5;
int d = 2;
int e = 0;
e = b + a;
System.out.println(a + "+" + b + "=" + e);
System.out.println("this is something I cant say in school:");
System.out.println("potato tits rat shit bat shit dirty old cunt 69 assholes tied in a knot hooray lizard piss FUCK");
}
}
public class JavaPractice001
{
public static void main(String args[])
{
int a = 25;
int b = 10;
int c = 5;
int d = 2;
int e = 0;
e = b + a;
System.out.println(a + "+" + b + "=" + e);
System.out.println("this is something I cant say in school:");
System.out.println("potato tits rat shit bat shit dirty old cunt 69 assholes tied in a knot hooray lizard piss FUCK");
}
}
Subscribe to:
Posts (Atom)