Advertisement
Montoya-Romina-Anahi

TP4_Punto7_Lista

Jun 19th, 2020
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. import java.util.LinkedList;
  2. import javax.swing.JOptionPane;
  3.  
  4.  
  5. public class Lista {
  6. String nombreEquipo;
  7. int integrantes,presas;
  8.  
  9. public Lista(){}
  10.  
  11. public Lista(String nombreEquipo,int integrantes,int presas){
  12. this.nombreEquipo = nombreEquipo;
  13. this.integrantes = integrantes;
  14. this.presas = presas;
  15. }
  16.  
  17. public int Menu(){
  18. int opcion = 0;
  19. try{
  20. opcion = Integer.parseInt(JOptionPane.showInputDialog(null,
  21. "1.-Agregar Equipo\n"+
  22. "2.-Mostrar Resultados\n"+
  23. "3.-Salir","Menu",3));
  24. }catch(NumberFormatException e){
  25. }finally{
  26. return opcion;
  27. }
  28. }
  29. private boolean ValidarIntegrantes(int integrantes){
  30. return (integrantes >= 3 && integrantes <=5);
  31. }
  32. private boolean ValidarPresas(int presas){
  33. return (presas >= 0);
  34. }
  35.  
  36. public Lista AgregarEquipo(Lista carga){
  37. try{
  38. carga.nombreEquipo = JOptionPane.showInputDialog(null,"Ingrece el nombre del equipo","Nombre del Equipo",3);
  39. carga.integrantes = Integer.parseInt(JOptionPane.showInputDialog(null,
  40. "Ingrece cantida de integrantes (min 3/max 5)",
  41. "Cantidad de Integrantes",3));
  42. carga.presas = Integer.parseInt(JOptionPane.showInputDialog(null,
  43. "Ingrece cantidad presas obtenidas",
  44. "Presas Obtenidas",3));
  45. if(this.ValidarIntegrantes(integrantes) && this.ValidarPresas(presas)){
  46. return carga;
  47. }else{
  48. return carga = null;
  49. }
  50. }catch(Exception e){
  51. return carga = null;
  52. }
  53. }
  54.  
  55. public Lista EncontrarGanador(LinkedList<Lista> listado){
  56. Lista ganador;
  57.  
  58. ganador = listado.get(0);
  59. for(int i=1;i<listado.size();i++){
  60. if(ganador.presas < listado.get(i).presas){
  61. ganador = listado.get(i);
  62. }
  63. }
  64. return ganador;
  65. }
  66.  
  67. public Lista EncontrarPeor(LinkedList<Lista> listado){
  68. Lista peor;
  69.  
  70. peor = listado.get(0);
  71. for(int i=1;i<listado.size();i++){
  72. if(peor.presas > listado.get(i).presas){
  73. peor = listado.get(i);
  74. }
  75. }
  76. return peor;
  77. }
  78.  
  79. /*Este metodo busca al equipo con menor cantidad
  80. *de integrantes y mayor catidad de presas
  81. */
  82. public Lista EncontarMejorMinimo(LinkedList<Lista> listado){
  83. Lista aux;
  84.  
  85. aux = listado.get(0);
  86. for(int i=1;i<listado.size();i++){
  87. if(aux.integrantes > listado.get(i).integrantes){
  88. aux = listado.get(i);
  89. }
  90. }
  91. return aux;
  92. }
  93.  
  94. public void MostrarEquipo(Lista equipo, String estado){
  95. JOptionPane.showMessageDialog(null, estado + "\n"+
  96. "Equipo: " + equipo.nombreEquipo + "\n" +
  97. "Cantidad de integrantes: " + Integer.toString(equipo.integrantes) + "\n" +
  98. "Cantidad de presas: " + Integer.toString(equipo.presas));
  99. }
  100.  
  101. public void MostrarResultados(LinkedList<Lista> listado){
  102. Lista aux;
  103.  
  104. aux = this.EncontrarGanador(listado);
  105. this.MostrarEquipo(aux,"Ganadores");
  106.  
  107. aux = this.EncontrarPeor(listado);
  108. this.MostrarEquipo(aux,"Peores");
  109.  
  110. aux = this.EncontarMejorMinimo(listado);
  111. this.MostrarEquipo(aux,"Mejores con menor equipo");
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement