Fixed Q1 calculations (though they could be simplified).
This commit is contained in:
parent
b5db1fbdc2
commit
497c7d0bea
@ -136,30 +136,58 @@ public class MMMCalc {
|
|||||||
|
|
||||||
// FIXME: Q1 calculates incorrectly, it is supposed to be halfway between the first variable and the median variable.
|
// FIXME: Q1 calculates incorrectly, it is supposed to be halfway between the first variable and the median variable.
|
||||||
private static void calcQ1() {
|
private static void calcQ1() {
|
||||||
int q1Pos = numArray.length / 4;
|
int q1Pos;
|
||||||
boolean exact;
|
// c stands for case... Cases correspond to their order in the following if statements (4 different cases).
|
||||||
|
int c;
|
||||||
|
|
||||||
if(numArray.length % 4 != 0) {
|
if(numArray.length % 2.0 == 0) {
|
||||||
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
|
q1Pos = (int)(numArray.length / 4);
|
||||||
exact = false;
|
if(numArray.length % 4.0 == 0) {
|
||||||
|
q1 = (numArray[q1Pos] + numArray[q1Pos-1]) / 2;
|
||||||
|
c = 1;
|
||||||
|
} else {
|
||||||
|
q1 = numArray[q1Pos];
|
||||||
|
c = 2;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
q1 = numArray[q1Pos];
|
if(Math.ceil(numArray.length / 2.0) % 2.0 == 0) {
|
||||||
exact = true;
|
q1Pos = (int)(Math.ceil(numArray.length / 2.0) / 2.0);
|
||||||
|
q1 = (numArray[q1Pos] + numArray[q1Pos+1]) / 2;
|
||||||
|
c = 3;
|
||||||
|
} else {
|
||||||
|
q1Pos = (int)Math.ceil(numArray.length / 4.0);
|
||||||
|
q1 = numArray[q1Pos];
|
||||||
|
c = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Q1: " + q1);
|
System.out.println("Q1: " + q1);
|
||||||
|
|
||||||
if(verbose) {
|
if(verbose) {
|
||||||
for(int i = 0; i < numArray.length; i++) {
|
for(int i = 0; i < numArray.length; i++) {
|
||||||
if(!exact) {
|
if(c == 1) {
|
||||||
if(i == q1Pos - 1) {
|
if(i == q1Pos - 1) {
|
||||||
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
||||||
} else if( i == q1Pos) {
|
} else if(i == q1Pos) {
|
||||||
System.out.print(numArray[i] + "<< ");
|
System.out.print(numArray[i] + "<< ");
|
||||||
} else {
|
} else {
|
||||||
System.out.print(numArray[i] + " ");
|
System.out.print(numArray[i] + " ");
|
||||||
}
|
}
|
||||||
} else {
|
} else if(c == 2) {
|
||||||
|
if(i == q1Pos) {
|
||||||
|
System.out.print(">>" + numArray[i] + "<< ");
|
||||||
|
} else {
|
||||||
|
System.out.print(numArray[i] + " ");
|
||||||
|
}
|
||||||
|
} else if(c == 3) {
|
||||||
|
if(i == q1Pos) {
|
||||||
|
System.out.print(">>" + numArray[i] + " !" + q1 + "! ");
|
||||||
|
} else if(i == q1Pos + 1) {
|
||||||
|
System.out.print(numArray[i] + "<< ");
|
||||||
|
} else {
|
||||||
|
System.out.print(numArray[i] + " ");
|
||||||
|
}
|
||||||
|
} else if(c == 4) {
|
||||||
if(i == q1Pos) {
|
if(i == q1Pos) {
|
||||||
System.out.print(">>" + numArray[i] + "<< ");
|
System.out.print(">>" + numArray[i] + "<< ");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user