Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. import javax.swing.*;
  2. public class Ejercicio1{
  3.  
  4. public static void main(String args[]){
  5.  
  6.  
  7. int puntos;
  8. int nJug;
  9.  
  10. String nombreJug="";
  11. int edadJug;
  12. float precioFicha;
  13. char posicionJug;
  14.  
  15. int goles;
  16. int penaltis;
  17.  
  18. int sumaEdad=0;
  19. int contDef=0;
  20. float mediaEdad=0;
  21.  
  22. float maxFicha=0;
  23. String jugMaxFicha="";
  24.  
  25. float relacionPuntosJug;
  26.  
  27. float rendimiento;
  28. float maxRendimiento=0;
  29. String equipoMaxRendimiento="";
  30.  
  31. boolean equipoTienePorteroOLateral=false;
  32. boolean hayEquipoSinPorteroNiLateral=false;
  33.  
  34. String mensajeEquipo="";
  35.  
  36. String nombreEquipo=JOptionPane.showInputDialog(null, "Nombre del equipo:");
  37. while (!nombreEquipo.equals("fin")){
  38.  
  39. puntos=Integer.parseInt(JOptionPane.showInputDialog(null, "Puntos del equipo:"));
  40. nJug=Integer.parseInt(JOptionPane.showInputDialog(null, "Numero de jugadores:"));
  41.  
  42. rendimiento=(float)puntos/nJug;
  43. if(rendimiento>maxRendimiento){
  44. maxRendimiento=rendimiento;
  45. equipoMaxRendimiento=nombreEquipo;
  46. }
  47.  
  48. equipoTienePorteroOLateral=false;
  49.  
  50. for (int i=0; i<nJug; i++){
  51.  
  52. nombreJug=JOptionPane.showInputDialog(null, "Nombre del jugador:");
  53. edadJug=Integer.parseInt(JOptionPane.showInputDialog(null, "Edad del jugador:"));
  54. precioFicha=Float.parseFloat(JOptionPane.showInputDialog(null, "Precio de su ficha:"));
  55. posicionJug=JOptionPane.showInputDialog(null, "Posicion del jugador:").charAt(0);
  56.  
  57. switch (posicionJug){
  58. case 'd':
  59. case 'D':
  60. goles=Integer.parseInt(JOptionPane.showInputDialog(null, "Goles marcados por el delantero:"));
  61. break;
  62. case 'p':
  63. case 'P':
  64. penaltis=Integer.parseInt(JOptionPane.showInputDialog(null, "Penaltis encajados por el portero:"));
  65. equipoTienePorteroOLateral=true;
  66. break;
  67. case 'f':
  68. case 'F':
  69. sumaEdad=sumaEdad+edadJug;
  70. contDef++;
  71. break;
  72. case 'l':
  73. case 'L':
  74. equipoTienePorteroOLateral=true;
  75. break;
  76.  
  77.  
  78. /*if (posicionJug.equalsIgnoreCase("d")){
  79. goles=Integer.parseInt(JOptionPane.showInputDialog(null, "Goles marcados por el delantero:"));
  80. }
  81.  
  82. else if (posicionJug.equalsIgnoreCase("p")){
  83. penaltis=Integer.parseInt(JOptionPane.showInputDialog(null, "Penaltis encajados por el portero:"));
  84. }
  85.  
  86. else if (posicionJug.equalsIgnoreCase("f")){
  87. sumaEdad=sumaEdad+edadJug;
  88. contDef++;*/
  89.  
  90.  
  91. }
  92.  
  93.  
  94. if ((nJug<7) && (precioFicha>maxFicha)){
  95. maxFicha=precioFicha;
  96. jugMaxFicha=nombreJug;
  97. }
  98.  
  99.  
  100. }
  101.  
  102. nombreEquipo=JOptionPane.showInputDialog(null, "Nombre del equipo:");
  103.  
  104. }
  105.  
  106. if (equipoTienePorteroOLateral==false){
  107. hayEquipoSinPorteroNiLateral=true;
  108. }
  109.  
  110.  
  111.  
  112. if (contDef>0){
  113. mediaEdad=(float)sumaEdad/contDef;
  114. }
  115.  
  116. if (hayEquipoSinPorteroNiLateral==true){
  117. mensajeEquipo="Hay al menos un equipo que no tiene ni portero ni laterales";
  118. }
  119. else{
  120. mensajeEquipo="No hay ningún equipo que no tenga portero ni laterales";
  121. }
  122.  
  123.  
  124. JOptionPane.showMessageDialog(null, "La media de la edad de los defensas es: "+mediaEdad+
  125. "\nJugador con la ficha mas cara en equipos de menos de 7 jugadores: "+jugMaxFicha+
  126. "\nEquipo con mas rendimiento: "+equipoMaxRendimiento+
  127. "\n"+mensajeEquipo);
  128.  
  129.  
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement