8 Commits
v0.2 ... v0.3

2 changed files with 120 additions and 1 deletions

View File

@ -3,4 +3,10 @@ MMMCalc
This is a very simple project, it was made for educational purposes (hence why it is open-source), and I encourage everyone to contribute if they have something to add.
The most simple way to build this project is to move to the src folder/directory and run
$ javac MMMCalc.java
This will allow you to build the project that should work properly if you are downloading one of the releases (if you download the straight from the master branch it might have some problems).
To contact me, send me an e-mail at <nicolas.ortega.froysa@gmail.com>.

View File

@ -14,7 +14,9 @@ public class MMMCalc {
private static boolean verbose = false;
private static float[] numArray;
private static float mean = 0;
private static float q1 = 0;
private static float median = 0;
private static float q3 = 0;
private static float mode = 0;
private static float range = 0;
private static float stdDev = 0;
@ -66,7 +68,9 @@ public class MMMCalc {
sortArray();
calcMean();
calcQ1();
calcMedian();
calcQ3();
calcMode();
calcRange();
calcStdDev();
@ -80,7 +84,9 @@ public class MMMCalc {
sortArray();
calcMean();
calcQ1();
calcMedian();
calcQ3();
calcMode();
calcRange();
calcStdDev();
@ -128,12 +134,112 @@ public class MMMCalc {
}
}
private static void calcQ1() {
int q1Pos = numArray.length / 4;
boolean exact;
if(numArray.length % 4 == 0) {
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
exact = false;
} else {
q1 = numArray[q1Pos];
exact = true;
}
System.out.println("Q1: " + q1);
if(verbose) {
for(int i = 0; i < numArray.length; i++) {
if(!exact) {
if(i == q1Pos - 1) {
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
} else if( i == q1Pos) {
System.out.print(numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
} else {
if(i == q1Pos) {
System.out.print(">>" + numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
}
}
System.out.print("\n\n");
}
}
private static void calcMedian() {
int midVar = numArray.length / 2;
boolean exact;
if(numArray.length % 2 == 0) {
median = (numArray[midVar] + numArray[midVar-1]) / 2;
exact = false;
} else {
median = numArray[midVar];
exact = true;
}
System.out.println("Median: " + median);
if(verbose) {
for(int i = 0; i < numArray.length; i++) {
if(!exact) {
if(i == midVar - 1) {
System.out.print(">>" + numArray[i] + " !" + median + "! ");
} else if(i == midVar) {
System.out.print(numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
} else {
if(i == midVar) {
System.out.print(">>" + numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
}
}
System.out.print("\n\n");
}
}
private static void calcQ3() {
int q3Pos = (numArray.length * 3) / 4;
boolean exact;
if((numArray.length * 3) % 4 == 0) {
q3 = (numArray[q3Pos] + numArray[q3Pos-1]) / 2;
exact = false;
} else {
q3 = numArray[q3Pos];
exact = true;
}
System.out.println("Q3: " + q3);
if(verbose) {
for(int i = 0; i < numArray.length; i++) {
if(!exact) {
if(i == q3Pos - 1) {
System.out.print(">>" + numArray[i] + " !" + q3 + "! ");
} else if(i == q3Pos) {
System.out.print(numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
} else {
if(i == q3Pos) {
System.out.print(">>" + numArray[i] + "<< ");
} else {
System.out.print(numArray[i] + " ");
}
}
}
System.out.print("\n\n");
}
}
private static void calcMode() {
@ -159,6 +265,13 @@ public class MMMCalc {
}
System.out.println("Mode: " + mode + " (frequency: " + modeFreq + ")");
if(verbose) {
for(Map.Entry<Float, Float> entry:fx.entrySet()) {
System.out.print(entry.getKey() + "(" + entry.getValue() + ") ");
}
System.out.print("\n\n");
}
}
private static void calcRange() {