Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class Ejercicio1{
- public static void main(String args[]){
- int puntos;
- int nJug;
- String nombreJug="";
- int edadJug;
- float precioFicha;
- char posicionJug;
- int goles;
- int penaltis;
- int sumaEdad=0;
- int contDef=0;
- float mediaEdad=0;
- float maxFicha=0;
- String jugMaxFicha="";
- float relacionPuntosJug;
- float rendimiento;
- float maxRendimiento=0;
- String equipoMaxRendimiento="";
- boolean equipoTienePorteroOLateral=false;
- boolean hayEquipoSinPorteroNiLateral=false;
- String mensajeEquipo="";
- String nombreEquipo=JOptionPane.showInputDialog(null, "Nombre del equipo:");
- while (!nombreEquipo.equals("fin")){
- puntos=Integer.parseInt(JOptionPane.showInputDialog(null, "Puntos del equipo:"));
- nJug=Integer.parseInt(JOptionPane.showInputDialog(null, "Numero de jugadores:"));
- rendimiento=(float)puntos/nJug;
- if(rendimiento>maxRendimiento){
- maxRendimiento=rendimiento;
- equipoMaxRendimiento=nombreEquipo;
- }
- equipoTienePorteroOLateral=false;
- for (int i=0; i<nJug; i++){
- nombreJug=JOptionPane.showInputDialog(null, "Nombre del jugador:");
- edadJug=Integer.parseInt(JOptionPane.showInputDialog(null, "Edad del jugador:"));
- precioFicha=Float.parseFloat(JOptionPane.showInputDialog(null, "Precio de su ficha:"));
- posicionJug=JOptionPane.showInputDialog(null, "Posicion del jugador:").charAt(0);
- switch (posicionJug){
- case 'd':
- case 'D':
- goles=Integer.parseInt(JOptionPane.showInputDialog(null, "Goles marcados por el delantero:"));
- break;
- case 'p':
- case 'P':
- penaltis=Integer.parseInt(JOptionPane.showInputDialog(null, "Penaltis encajados por el portero:"));
- equipoTienePorteroOLateral=true;
- break;
- case 'f':
- case 'F':
- sumaEdad=sumaEdad+edadJug;
- contDef++;
- break;
- case 'l':
- case 'L':
- equipoTienePorteroOLateral=true;
- break;
- /*if (posicionJug.equalsIgnoreCase("d")){
- goles=Integer.parseInt(JOptionPane.showInputDialog(null, "Goles marcados por el delantero:"));
- }
- else if (posicionJug.equalsIgnoreCase("p")){
- penaltis=Integer.parseInt(JOptionPane.showInputDialog(null, "Penaltis encajados por el portero:"));
- }
- else if (posicionJug.equalsIgnoreCase("f")){
- sumaEdad=sumaEdad+edadJug;
- contDef++;*/
- }
- if ((nJug<7) && (precioFicha>maxFicha)){
- maxFicha=precioFicha;
- jugMaxFicha=nombreJug;
- }
- }
- nombreEquipo=JOptionPane.showInputDialog(null, "Nombre del equipo:");
- }
- if (equipoTienePorteroOLateral==false){
- hayEquipoSinPorteroNiLateral=true;
- }
- if (contDef>0){
- mediaEdad=(float)sumaEdad/contDef;
- }
- if (hayEquipoSinPorteroNiLateral==true){
- mensajeEquipo="Hay al menos un equipo que no tiene ni portero ni laterales";
- }
- else{
- mensajeEquipo="No hay ningún equipo que no tenga portero ni laterales";
- }
- JOptionPane.showMessageDialog(null, "La media de la edad de los defensas es: "+mediaEdad+
- "\nJugador con la ficha mas cara en equipos de menos de 7 jugadores: "+jugMaxFicha+
- "\nEquipo con mas rendimiento: "+equipoMaxRendimiento+
- "\n"+mensajeEquipo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement