This commit is contained in:
Orange 2016-11-22 18:43:02 +01:00
parent 9290c7403f
commit 74cdd20296
2 changed files with 38 additions and 1 deletions

View File

@ -34,6 +34,39 @@ public class Concessionaria{
} }
} }
public boolean swap(int i){
Auto tmp=auto.get(i);
auto.set(i, auto.get(i+1));
auto.set(i+1, tmp);
return false;
}
public Concessionaria sortDecrescente(){
boolean ordinato;
int j=auto.size()-1;
do{
ordinato=true;
for(int i=0; i<j; i++)
if(auto.get(i).getPrezzo()<auto.get(i+1).getPrezzo())
ordinato=swap(i);
}while(j-->1 && !ordinato);
return new Concessionaria(auto);
}
public Concessionaria sortCrescente(){
boolean ordinato;
int j=auto.size()-1;
do{
ordinato=true;
for(int i=0; i<j; i++)
if(auto.get(i).getPrezzo()>auto.get(i+1).getPrezzo())
ordinato=swap(i);
}while(j-->1 && !ordinato);
return new Concessionaria(auto);
}
public Concessionaria filtroUsato(){ public Concessionaria filtroUsato(){
ArrayList<Auto> autoFilter = new ArrayList<Auto>(); ArrayList<Auto> autoFilter = new ArrayList<Auto>();
for(Auto a: auto) for(Auto a: auto)

View File

@ -7,6 +7,10 @@ public class Test{
Scanner scNuove = new Scanner(new File("nuove.dat")); Scanner scNuove = new Scanner(new File("nuove.dat"));
Scanner scUsate = new Scanner(new File("usate.dat")); Scanner scUsate = new Scanner(new File("usate.dat"));
Concessionaria con = new Concessionaria(scNuove, scUsate); Concessionaria con = new Concessionaria(scNuove, scUsate);
con.filtroAnnoImmatricolazione(2015).print(System.out); //con.filtroAnnoImmatricolazione(2015).print(System.out);
System.out.println("Decrescente");
con.sortDecrescente().print(System.out);
System.out.println("Crescente");
con.sortCrescente().print(System.out);
} }
} }