package formula1; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; public class Campionato { private ArrayList piloti=new ArrayList(); private ArrayList gp=new ArrayList(); /** * Crea un nuovo pilota e lo inserirsce nel campionato * @param nome il nome del pilota (Es. "Barrichello") */ public Pilota creaPilota(String nome) { // TODO Auto-generated method stub Pilota pilota =new Pilota(nome,this); piloti.add(pilota); return pilota; } /** * @return un elenco di oggetti Pilota */ public Collection getPiloti() { // TODO Auto-generated method stub return piloti; } /** * @param nome il nome del pilota * @return l'oggetto Pilota corrispondente */ public Pilota getPilota(String nome) { // TODO Auto-generated method stub boolean found=false; Pilota p=null; Iterator it=piloti.iterator(); while(it.hasNext() && !found){ p=(Pilota) it.next(); if(nome.compareTo(p.getNome())==0) found=true; } return p; } /** * @param nome il nome del gran premio (Es. "Imola") * @return l'oggetto GP corrispondente */ public GP definisciGranPremio(String nome) { // TODO Auto-generated method stub GP gran=new GP(nome); gp.add(gran); return gran; } /** * @param nome nome del GP * @return l'oggetto GP corrispondente */ public GP getGranPremio(String nome) { // TODO Auto-generated method stub boolean found=false; GP p=null; Iterator it=gp.iterator(); while(it.hasNext() && !found){ p=(GP) it.next(); if(nome.compareTo(p.getNome())==0) found=true; } return p; } /** * @param gp * @param r * @param hours * @param min * @param sec * @param cent * @return */ public Tempo setTempo(GP gp, Pilota r, int hours, int min, int sec, int cent) throws TempoNonValido{ // TODO Auto-generated method stub Tempo t=null; if(min>=0 && min<60 && sec>=0 && sec<60 && cent>=0 && cent<100){ t=new Tempo(hours,min,sec,cent); //passo al pilota il suo tempo del gran premio r.settempo(gp,t); //passo al gran premio il pilota e il suo tempo gp.setarrivo(r,t); Collections.sort(piloti, new Comparator(){ public int compare(Object o1, Object o2){ Pilota ob1=(Pilota) o1; Pilota ob2=(Pilota) o2; return ob2.getPunti()-ob1.getPunti(); } }); } else{ throw new TempoNonValido(); } return t; } /** * @return lista dei piloti ordinati in base ai punti totalizzati * ovvero al risultato del metodo getPunti() di Pilota */ public List getClassifica() { // TODO Auto-generated method stub return null; } /** * @param file path del file con informazioni su piloti e GP */ public void leggiInfo(String file) { // TODO Auto-generated method stub String path= file.substring(0,file.lastIndexOf("/")); String nome= file.substring(file.lastIndexOf("/")+1,file.length()); File f=new File(path,nome); } }