This commit is contained in:
orange 2017-01-08 18:19:25 +01:00
parent 74b404f03f
commit 89479bf7fa
5 changed files with 64 additions and 10 deletions

29
src/Mediana.java Normal file
View File

@ -0,0 +1,29 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Random;
public class Mediana{
public static void main(String [] args){
ArrayList<Integer> list =new ArrayList<Integer>();
Random rand = new Random();
for(int i=0; i<rand.nextInt(100); i++){
list.add(rand.nextInt(100));
}
Comparator<Integer> cmp=new IntComparator();
Collections.sort(list, cmp);
for(Integer item: list){
System.out.println(item);
}
}
}
class IntComparator implements Comparator<Integer>{
public int compare(Integer i1, Integer i2){
return (-1)*i1.compareTo(i2);
}
}

View File

@ -1,11 +1,15 @@
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Set;
import java.util.TreeSet;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
public class Anagrafe{
public Anagrafe(Scanner sc)throws Exception{
registro = new ArrayList<Persona>();
Comparator<Persona> cmp=new PersonaComparator();
registro = new TreeSet<Persona>(cmp);
Persona p = Persona.read(sc);
while(p!=null){
registro.add(p);
@ -14,7 +18,7 @@ public class Anagrafe{
}
private Anagrafe(ArrayList<Persona> registro){
this.registro=registro;
//this.registro=registro;
}
public void print(PrintStream ps){
@ -43,6 +47,19 @@ public class Anagrafe{
}
private ArrayList<Persona> registro;
private Set<Persona> registro;
}
class PersonaComparator implements Comparator<Persona>{
public int compare(Persona p1, Persona p2){
int cmp=p1.getDataDiNascita().compareTo(p2.getDataDiNascita());
if(cmp==0){
cmp=p1.getCognome().compareTo(p2.getCognome());
if(cmp==0){
cmp=p1.getNome().compareTo(p2.getNome());
}
}
return cmp;
}
}

View File

@ -49,6 +49,7 @@ public class Persona{
ps.println(nome);
ps.println(cognome);
ps.println(sdf.format(dataDiNascita));
ps.println("*****");
}

View File

@ -7,7 +7,5 @@ public class Test{
Scanner sc = new Scanner(fl);
Anagrafe an=new Anagrafe(sc);
an.print(System.out);
System.out.println("*******");
an.filtroCognome("due").filtroNome("noemi").print(System.out);
}
}

View File

@ -1,9 +1,18 @@
pappa
papsp
Raffaele
Mignone
12/12/1999
dffdfd
dhdhdh
Aaa
Manganiello
14/08/1990
Salvatore
Manganiello
14/08/1990
Francesco
Martignetti
15/08/1990
Raffaele
Mignone
12/12/2000
noemi
dhhf
13/05/1200