Created
April 24, 2015 11:22
-
-
Save delucas/71d0882315ebf58576c3 to your computer and use it in GitHub Desktop.
Analizador Estadístico - UNTreF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Assert; | |
import org.junit.Test; | |
public class AETests { | |
@Test | |
public void queCalcula() { | |
MuestraDePersonas m = new MuestraDePersonas(2); | |
m.agregarPersona(new Persona(100, 123)); | |
m.agregarPersona(new Persona(110, 125)); | |
AnalizadorEstadistico a = | |
new AnalizadorEstadistico(m.recolectarIQ()); | |
Assert.assertEquals(105, a.getMedia(), 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AnalizadorEstadistico { | |
private int[] valores; | |
public AnalizadorEstadistico(int[] valores) { | |
this.valores = valores; | |
} | |
public double getMedia(){ | |
double suma = 0; | |
for (int valor : this.valores) { | |
suma += valor; | |
} | |
return suma / this.valores.length; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MuestraDePersonas { | |
private Persona[] personas; | |
private int posicionProximaPersona = 0; | |
public MuestraDePersonas(final int cantidadPersonas) { | |
this.personas = new Persona[cantidadPersonas]; | |
} | |
public void agregarPersona(Persona p) { | |
this.personas[posicionProximaPersona++] = p; | |
} | |
public int[] recolectarIQ(){ | |
int[] tmp = new int[this.personas.length]; | |
for (int i = 0; i < this.personas.length; i++) { | |
tmp[i] = this.personas[i].getIq(); | |
} | |
return tmp ; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Persona { | |
private int iq; | |
private int altura; | |
public Persona(int iq, int altura) { | |
this.iq = iq; | |
this.altura = altura; | |
} | |
public int getIq() { | |
return iq; | |
} | |
public int getAltura() { | |
return altura; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment