There is now a verbose mode for Q1 and Q3.

This commit is contained in:
Deathsbreed 2014-04-14 17:36:28 -05:00
parent cbe1aeb123
commit 0ce346b714

View File

@ -136,37 +136,57 @@ public class MMMCalc {
private static void calcQ1() { private static void calcQ1() {
int q1Pos = numArray.length / 4; int q1Pos = numArray.length / 4;
boolean exact;
if(numArray.length % 4 == 0) { if(numArray.length % 4 == 0) {
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2; q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
exact = false;
} else { } else {
q1 = numArray[q1Pos]; q1 = numArray[q1Pos];
exact = true;
} }
System.out.println("Q1: " + q1); System.out.println("Q1: " + q1);
if(verbose) { if(verbose) {
// Add verbose stuff here. 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() { private static void calcMedian() {
int midVar = numArray.length / 2; int midVar = numArray.length / 2;
boolean even; boolean exact;
if(numArray.length % 2 == 0) { if(numArray.length % 2 == 0) {
median = (numArray[midVar] + numArray[midVar-1]) / 2; median = (numArray[midVar] + numArray[midVar-1]) / 2;
even = true; exact = false;
} else { } else {
median = numArray[midVar]; median = numArray[midVar];
even = false; exact = true;
} }
System.out.println("Median: " + median); System.out.println("Median: " + median);
if(verbose) { if(verbose) {
for(int i = 0; i < numArray.length; i++) { for(int i = 0; i < numArray.length; i++) {
if(even) { if(!exact) {
if(i == midVar - 1) { if(i == midVar - 1) {
System.out.print(">>" + numArray[i] + " !" + median + "! "); System.out.print(">>" + numArray[i] + " !" + median + "! ");
} else if(i == midVar) { } else if(i == midVar) {
@ -188,17 +208,37 @@ public class MMMCalc {
private static void calcQ3() { private static void calcQ3() {
int q3Pos = (numArray.length * 3) / 4; int q3Pos = (numArray.length * 3) / 4;
boolean exact;
if((numArray.length * 3) % 4 == 0) { if((numArray.length * 3) % 4 == 0) {
q3 = (numArray[q3Pos] + numArray[q3Pos-1]) / 2; q3 = (numArray[q3Pos] + numArray[q3Pos-1]) / 2;
exact = false;
} else { } else {
q3 = numArray[q3Pos]; q3 = numArray[q3Pos];
exact = true;
} }
System.out.println("Q3: " + q3); System.out.println("Q3: " + q3);
if(verbose) { if(verbose) {
// Add verbose stuff here. 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");
} }
} }