Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. ESTE METODO RECORRE MI ARREGLO DE GENOTIPOS Y ME DICE SI LO QUE ENTRA COMO PARAMETRO ES IGUAL O NO A LO QUE GUARDE EN EL ARREGLO
  2.  
  3.  
  4. public boolean esCorrecto (String info) throws Exception
  5. {
  6. boolean seAcepta = false;
  7. for(int i = 0 ; i< darGenotipo().length && seAcepta == false ; i++)
  8. {
  9. String genotipo = darGenotipo()[i].darAlelo();
  10. if(info.equals(genotipo))
  11. {
  12. seAcepta = true;
  13. }
  14. }
  15. if(seAcepta == false)
  16. {
  17. throw new Exception ("Porfavor ingrese un fenotipo valido");
  18. }
  19. else
  20. return seAcepta;
  21. }
  22.  
  23. Y EL CREAR ENTONCS ME QUEDARIA ASI EN LA INTERFAZ, EL DEL MUNDO ES EL QUE USTED YA TIENE EL FELICIDAD 2 JAJA
  24.  
  25. public void crear()
  26. {
  27. String padre = (String)JOptionPane.showInputDialog(this, "Genotipo Padre: ", "Crear Cuadro de Punnett", JOptionPane.QUESTION_MESSAGE);
  28.  
  29. try
  30. {
  31. esCorrecto(padre);
  32.  
  33. if(padre != null && !padre.equals("") )
  34. {
  35. String madre = (String)JOptionPane.showInputDialog(this, "Genotipo Madre: ", "Crear Cuadro de Punnett" , JOptionPane.QUESTION_MESSAGE);
  36.  
  37. try
  38. {
  39. esCorrecto(madre);
  40.  
  41. if(madre!=null && !madre.equals(""))
  42. {
  43. calculadoraPunnett.crear(padre, madre);
  44. }
  45. }
  46.  
  47. catch(Exception e)
  48. {
  49.  
  50. }
  51. // Tuve que hacer este condicional porque si lo dejaba que fuera manejado por el catch,
  52. // siempre me iba a salir la excepcion sin importar que el fenotipo estuviese escrito bien.
  53. // No entiendo porque sucede esto, y lo revise de muchas maneras.
  54. if( esCorrecto(madre) == false)
  55. {
  56. JOptionPane.showMessageDialog(this, "Por favor ingrese un fenotipo valido " , "Error", JOptionPane.ERROR_MESSAGE);
  57. }
  58. }
  59.  
  60. }
  61. catch(Exception e)
  62. {
  63. JOptionPane.showMessageDialog(this, e.getMessage() , "Error", JOptionPane.ERROR_MESSAGE);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement