Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package uniandes.cupi2.calculadoraPunnett.mundo;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.util.Properties;
  6.  
  7. public class Calculadora
  8. {
  9.    
  10.     //Constantes
  11.    
  12.     public final static int MAX_X= 4;
  13.    
  14.     public final static int MAX_Y= 4;
  15.    
  16.         //----------------------------------------------------------------
  17.         // Atributos
  18.         //----------------------------------------------------------------
  19.     private GenesHappys[][] genX;
  20.    
  21.     private String[] mamiSepsi;
  22.    
  23.     private String[] papiSepsi;
  24.    
  25.    
  26.    
  27.    
  28.     public Calculadora(String x ,String y , File arch) throws Exception
  29.     {
  30.         Properties datos = cargarInfoCalculadora( arch );        
  31.         calcularMami(x);
  32.         calcularPapi(y);
  33.         inicializarGenesHappys( datos );
  34.        
  35.     }
  36.    
  37.     private void inicializarGenesHappys(Properties datos)
  38.     {
  39.         genX = new GenesHappys[MAX_Y][MAX_X];
  40.         for(int i =0; i < MAX_Y ; i++)
  41.         {
  42.             for(int j =0; j < MAX_X ; j++)
  43.             {
  44.                 genX[i][j] = new GenesHappys( datos, "" + mamiSepsi[j].charAt(0)+ papiSepsi[i].charAt(0) + mamiSepsi[j].charAt(1)+ papiSepsi[i].charAt(1));
  45.             }
  46.            
  47.         }
  48.     }
  49.  
  50.     /**
  51.      * Carga la información de los equipos del campeonato en un objeto de tipo Properties.
  52.      * @param arch Es el archivo que contiene la descripción de los equipos del campeonato
  53.      * @return un objeto de la clase Properties con la información del archivo.
  54.      * @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.
  55.      */
  56.     private Properties cargarInfoCalculadora( File arch ) throws Exception
  57.     {
  58.         Properties datos = new Properties( );
  59.         FileInputStream in = new FileInputStream( arch );
  60.         try
  61.         {
  62.             datos.load( in );
  63.             in.close( );
  64.         }
  65.         catch( Exception e )
  66.         {
  67.             throw new Exception( "Formato inválido" );
  68.         }
  69.         return datos;
  70.     }
  71.    
  72.    
  73.     private void calcularMami(String x)
  74.     {
  75.         mamiSepsi[0] = "" +x.charAt(0) + x.charAt(2);  
  76.         mamiSepsi[1] = "" +x.charAt(0) + x.charAt(3);  
  77.         mamiSepsi[2] = "" +x.charAt(1) + x.charAt(2);  
  78.         mamiSepsi[2] = "" +x.charAt(1) + x.charAt(3);  
  79.     }
  80.    
  81.     private void calcularPapi(String y)
  82.     {
  83.         papiSepsi[0] = "" +y.charAt(0) + y.charAt(2);  
  84.         papiSepsi[1] = "" +y.charAt(0) + y.charAt(3);  
  85.         papiSepsi[2] = "" +y.charAt(1) + y.charAt(2);  
  86.         papiSepsi[3] = "" +y.charAt(1) + y.charAt(3);  
  87.                
  88.     }
  89.    
  90.     public double calcularProbabilidad(String color, String textura)
  91.     {
  92.         int casosChocoChevres = 0;
  93.         for(int i = 0; i < MAX_Y; i++)
  94.         {
  95.             for(int j = 0; j < MAX_X ; j++)
  96.             {
  97.                 if(genX[i][j].darColor().equals(color)&& genX[i][j].darTextura().equals(textura))
  98.                 {
  99.                     casosChocoChevres++;
  100.                 }
  101.                          
  102.             }
  103.         }
  104.         return (casosChocoChevres*100.0)/16;
  105.        
  106.     }
  107.    
  108.     public void borrarWuuu()
  109.     {
  110.         for(int i = 0; i < MAX_Y ; i++)
  111.         {
  112.             for(int j = 0; j < MAX_X ; j++)
  113.             {
  114.                 genX[i][j] = new GenesHappys(null,"");
  115.                 mamiSepsi[i] = "";
  116.                 papiSepsi[i] = "";
  117.                
  118.             }
  119.         }
  120.        
  121.     }
  122.    
  123.    
  124.    
  125.    
  126.    
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement