Sie sind auf Seite 1von 4

lAB6.

java

package lab6;

import java.util.Scanner;

/**
*
* @author ambuq
*/
public class Lab6 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int opc;
Atleta atl[] = null;
int cantidad_A = 0;
Competencia comp = new Competencia();
String nomCompetencia = "";
double tiempo = 1500;
do{
System.out.println("1.REGISTRAR ATLETA");
System.out.println("2.DATOS DEL CAMPEON");
System.out.println("3.ATLETAS POR PAIS");
System.out.println("4.TIEMPO PROMEDIO DE TODOS LOS ATLETAS");
System.out.println("5.SALIR\n");

System.out.print("DIGITE OPCION: ");


Scanner sc = new Scanner(System.in);
opc = sc.nextInt();

if(opc == 1){
System.out.print("DIGITE NOMBRE DE LA COMPETENCIA: ");
nomCompetencia = sc.nextLine();
comp.setNomCompetencia(nomCompetencia);
sc.nextLine();
System.out.print("DIGITE CANTIDAD DE PARTICIPANTES: ");
cantidad_A = sc.nextInt();
atl = new Atleta[cantidad_A];

for(int i = 0; i< cantidad_A ; i++){


System.out.print("DIGITE NOMBRES DEL ATLETA: ");
String nom = sc.next();
sc.nextLine();
System.out.print("DIGITE NACIONALIDAD DEL ATLETA: ");
String nac = sc.next();
sc.nextLine();
System.out.print("DIGITE TIEMPO DEL ATLETA: ");
double tmp = sc.nextDouble();
atl[i] = new Atleta(nom, nac, tmp);
System.out.println("-----------------------------------");

if(atl[i].getTmp() < tiempo){


tiempo = atl[i].getTmp();
comp.setAtl(atl[i]);
}
}
}else if(opc == 2){
if (atl != null){
System.out.println("-----------------------------------");
System.out.println(comp.getNomCompetencia());
System.out.println("DATOS DEL CAMPEON :");
System.out.println("Nombre :"+comp.getAtl().getNom()+"
Nacionalidad :"+comp.getAtl().getNac()+
" Tiempo :"+comp.getAtl().getTmp() );
System.out.println("-----------------------------------");
}else{
System.out.println("-----------------------------------");
System.out.println("NO HAY ATLETAS REGISTRADOS");
System.out.println("-----------------------------------");
}
}else if(opc == 3){
if (atl != null){
System.out.println("-----------------------------------");
System.out.print("DIGITE LA NACIONALIDAD: ");
String nacionalidad = sc.next();
for(Atleta a : atl ){
if(nacionalidad.equals(a.getNac())){
System.out.println("NOMBRE DEL ATLETA: "+a.getNom());

}
}

System.out.println("-----------------------------------");
}else{
System.out.println("-----------------------------------");
System.out.println("NO HAY ATLETAS REGISTRADOS");
System.out.println("-----------------------------------");
}
}else if(opc == 4){
double sumaTiempo = 0;
if (atl != null){
System.out.println("-----------------------------------");
for(Atleta a : atl ){
sumaTiempo = sumaTiempo+a.getTmp();
}
sumaTiempo = sumaTiempo / atl.length;
System.out.println("EL PROMEDIO DE LOS TIEMPOS ES:
"+sumaTiempo);
System.out.println("-----------------------------------");
}else{
System.out.println("-----------------------------------");
System.out.println("NO HAY ATLETAS REGISTRADOS");
System.out.println("-----------------------------------");
}
}
}while(opc !=5);

}
___________________________________________________________________________________
____

Atleta.java

package lab6;

/**
*
* @author ambuq
*/
public class Atleta {
String nom;
String nac;
double tmp;

public void setNom(String nom) {


this.nom = nom;
}

public void setNac(String nac) {


this.nac = nac;
}

public void setTmp(double tmp) {


this.tmp = tmp;
}

public Atleta(String nom, String nac, double tmp) {


this.nom = nom;
this.nac = nac;
this.tmp = tmp;
}

public String getNom() {


return nom;
}

public String getNac() {


return nac;
}

public double getTmp() {


return tmp;
}

___________________________________________________________________________________
___________________________

Competencia.java
package lab6;

/**
*
* @author ambuq
*/
public class Competencia {
Atleta atl;
String nomCompetencia;

public Competencia() {
}

public void setAtl(Atleta atl) {


this.atl = atl;
}

public void setNomCompetencia(String nomCompetencia) {


this.nomCompetencia = nomCompetencia;
}

public Atleta getAtl() {


return atl;
}

public String getNomCompetencia() {


return nomCompetencia;
}

Das könnte Ihnen auch gefallen