Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uniandes.cupi2.calculadoraPunnett.mundo;
- import java.io.File;
- import java.io.FileInputStream;
- import java.util.Properties;
- public class Calculadora
- {
- //Constantes
- public final static int MAX_X= 4;
- public final static int MAX_Y= 4;
- //----------------------------------------------------------------
- // Atributos
- //----------------------------------------------------------------
- private GenesHappys[][] genX;
- private String[] mamiSepsi;
- private String[] papiSepsi;
- public Calculadora(String x ,String y , File arch) throws Exception
- {
- Properties datos = cargarInfoCalculadora( arch );
- calcularMami(x);
- calcularPapi(y);
- inicializarGenesHappys( datos );
- }
- private void inicializarGenesHappys(Properties datos)
- {
- genX = new GenesHappys[MAX_Y][MAX_X];
- for(int i =0; i < MAX_Y ; i++)
- {
- for(int j =0; j < MAX_X ; j++)
- {
- genX[i][j] = new GenesHappys( datos, "" + mamiSepsi[j].charAt(0)+ papiSepsi[i].charAt(0) + mamiSepsi[j].charAt(1)+ papiSepsi[i].charAt(1));
- }
- }
- }
- /**
- * Carga la información de los equipos del campeonato en un objeto de tipo Properties.
- * @param arch Es el archivo que contiene la descripción de los equipos del campeonato
- * @return un objeto de la clase Properties con la información del archivo.
- * @throws Exception Se lanza esta excepción si el archivo no existe o si el formato del archivo no es válido y no puede ser leído.
- */
- private Properties cargarInfoCalculadora( File arch ) throws Exception
- {
- Properties datos = new Properties( );
- FileInputStream in = new FileInputStream( arch );
- try
- {
- datos.load( in );
- in.close( );
- }
- catch( Exception e )
- {
- throw new Exception( "Formato inválido" );
- }
- return datos;
- }
- private void calcularMami(String x)
- {
- mamiSepsi[0] = "" +x.charAt(0) + x.charAt(2);
- mamiSepsi[1] = "" +x.charAt(0) + x.charAt(3);
- mamiSepsi[2] = "" +x.charAt(1) + x.charAt(2);
- mamiSepsi[2] = "" +x.charAt(1) + x.charAt(3);
- }
- private void calcularPapi(String y)
- {
- papiSepsi[0] = "" +y.charAt(0) + y.charAt(2);
- papiSepsi[1] = "" +y.charAt(0) + y.charAt(3);
- papiSepsi[2] = "" +y.charAt(1) + y.charAt(2);
- papiSepsi[3] = "" +y.charAt(1) + y.charAt(3);
- }
- public double calcularProbabilidad(String color, String textura)
- {
- int casosChocoChevres = 0;
- for(int i = 0; i < MAX_Y; i++)
- {
- for(int j = 0; j < MAX_X ; j++)
- {
- if(genX[i][j].darColor().equals(color)&& genX[i][j].darTextura().equals(textura))
- {
- casosChocoChevres++;
- }
- }
- }
- return (casosChocoChevres*100.0)/16;
- }
- public void borrarWuuu()
- {
- for(int i = 0; i < MAX_Y ; i++)
- {
- for(int j = 0; j < MAX_X ; j++)
- {
- genX[i][j] = new GenesHappys(null,"");
- mamiSepsi[i] = "";
- papiSepsi[i] = "";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement