diff --git a/src/Studenti-Esami/Esame.class b/src/Studenti-Esami/Esame.class deleted file mode 100644 index 31c613b..0000000 Binary files a/src/Studenti-Esami/Esame.class and /dev/null differ diff --git a/src/Studenti-Esami/Esame.java b/src/Studenti-Esami/Esame.java index f25a3b0..9881219 100644 --- a/src/Studenti-Esami/Esame.java +++ b/src/Studenti-Esami/Esame.java @@ -1,49 +1,59 @@ import java.util.Scanner; +import java.io.PrintStream; public class Esame{ - public Esame(String nome, int voto, int mat){ - this.nome=nome; + public Esame(int matricola, String nomeEsame, String data, int voto){ + this.nomeEsame=nomeEsame; this.voto=voto; - this.mat=mat; + this.matricola=matricola; + this.data=data; } public int getVoto(){ return voto; } - public int getMat(){ - return mat; + public int getMatricola(){ + return matricola; } - public String getNome(){ - return nome; + public String getNomeEsame(){ + return nomeEsame; } - public boolean lookUp(int mat){ - if(this.mat==mat) - return true; - return false; + public String getData(){ + return data; + } + + public String toString(){ + return matricola + " " + nomeEsame + " " + data + " " + voto; + } + + public void print(PrintStream ps){ + ps.println(toString()); } public static Esame read(Scanner sc) throws Exception{ - String nome; + String nomeEsame; int voto; - int mat; - if(sc.hasNext()){ - nome=sc.next(); - if(sc.hasNextInt()){ - voto=sc.nextInt(); - if(sc.hasNextInt()){ - mat=sc.nextInt(); - return new Esame(nome, voto, mat); - } - } - } - return null; + int matricola; + String data; + + if(!sc.hasNextInt()) return null; + matricola=sc.nextInt(); + if(!sc.hasNext()) return null; + nomeEsame=sc.next(); + if(!sc.hasNext()) return null; + data=sc.next(); + if(!sc.hasNextInt()) return null; + voto=sc.nextInt(); + + return new Esame(matricola, nomeEsame, data, voto); } - private String nome; + private String nomeEsame; + private String data; private int voto; - private int mat; + private int matricola; } diff --git a/src/Studenti-Esami/Esami.dati b/src/Studenti-Esami/Esami.dati index 51444d9..e137268 100644 --- a/src/Studenti-Esami/Esami.dati +++ b/src/Studenti-Esami/Esami.dati @@ -1,12 +1,6 @@ -Chimica -18 -1313 -Economia -25 -1212 -Economia -30 -1414 -Chimica -30 -1212 +1313 Chimica 24-10-2016 18 +1212 Economia 25-12-2016 25 +1414 Economia 16-09-2016 30 +1212 Chimica 12-12-2016 30 +1212 Cucina 03-04-2016 30 +1313 Cucina 12-06-2016 27 diff --git a/src/Studenti-Esami/Main.class b/src/Studenti-Esami/Main.class deleted file mode 100644 index e58ab62..0000000 Binary files a/src/Studenti-Esami/Main.class and /dev/null differ diff --git a/src/Studenti-Esami/Main.java b/src/Studenti-Esami/Main.java deleted file mode 100644 index b9c76a3..0000000 --- a/src/Studenti-Esami/Main.java +++ /dev/null @@ -1,43 +0,0 @@ -import java.util.Scanner; -import java.io.*; - -public class Main{ - public static void main(String [] args) throws Exception{ - File srcStudenti = new File("Studenti.dati"); - File srcEsami = new File("Esami.dati"); - Scanner sc = new Scanner(System.in); - Esame e; - Studente s; - int i=0; - double media=0; - String nome, cnome; - - System.out.println("Inserisci il nome dello studente"); - nome=sc.nextLine(); - System.out.println("Inserisci il cognome dello studente"); - cnome=sc.nextLine(); - - sc=new Scanner(srcStudenti); - s=Studente.read(sc); - while(s!=null){ - if(s.lookUp(nome, cnome)){ - sc=new Scanner(srcEsami); - e=Esame.read(sc); - while(e!=null){ - if(e.lookUp(s.getMat())){ - media+=e.getVoto(); - i++; - } - e=Esame.read(sc); - } - break; - } - s=Studente.read(sc); - } - - if(s!=null) - System.out.println("lo studente "+s.getNomeCognome()+" ha la media di: "+media/i); - else - System.out.println("Impossibile trovare delle corrispondenze."); - } -} diff --git a/src/Studenti-Esami/Segreteria.java b/src/Studenti-Esami/Segreteria.java new file mode 100644 index 0000000..6ae1745 --- /dev/null +++ b/src/Studenti-Esami/Segreteria.java @@ -0,0 +1,105 @@ +import java.util.Scanner; +import java.util.ArrayList; +import java.io.*; + +public class Segreteria{ + + public Segreteria(String srcEsami, String srcStudenti) throws Exception{ + esami = new ArrayList(); + studenti = new ArrayList(); + Esame e; + Studente s; + + Scanner sc = new Scanner(new File(srcEsami)); + e=Esame.read(sc); + while(e!=null){ + esami.add(e); + e=Esame.read(sc); + } + + sc = new Scanner(new File(srcStudenti)); + s=Studente.read(sc); + while(s!=null){ + studenti.add(s); + s=Studente.read(sc); + } + } + + private Segreteria(ArrayList esami, ArrayList studenti){ + this.esami=esami; + this.studenti=studenti; + } + + public void print(PrintStream ps){ + for(Studente s: studenti) + s.print(ps); + + for(Esame e: esami) + e.print(ps); + } + + public Segreteria filtroMaggioreVoto(int voto){ + ArrayList esami = new ArrayList(); + + for(Esame e: this.esami){ + if(e.getVoto()>=voto) + esami.add(e); + } + + if(esami.size()==0) return null; + return new Segreteria(esami, this.studenti); + } + + public Segreteria filtroMinoreVoto(int voto){ + ArrayList esami = new ArrayList(); + + for(Esame e: this.esami){ + if(e.getVoto() esami = new ArrayList(); + ArrayList studenti = new ArrayList(); + int i=0; + boolean trovato=false; + + for(Esame e: this.esami){ + if(e.getMatricola()==matricola) + esami.add(e); + } + + while(i esami; + private ArrayList studenti; +} diff --git a/src/Studenti-Esami/Studente.class b/src/Studenti-Esami/Studente.class deleted file mode 100644 index 2d3e704..0000000 Binary files a/src/Studenti-Esami/Studente.class and /dev/null differ diff --git a/src/Studenti-Esami/Studente.java b/src/Studenti-Esami/Studente.java index 7e5e3e6..5253c13 100644 --- a/src/Studenti-Esami/Studente.java +++ b/src/Studenti-Esami/Studente.java @@ -1,45 +1,50 @@ import java.util.Scanner; +import java.io.PrintStream; public class Studente{ - public Studente(String nome, String cnome, int mat){ + public Studente(String nome, String cnome, int matricola){ this.nome=nome; this.cnome=cnome; - this.mat=mat; + this.matricola=matricola; } - public int getMat(){ - return mat; + public int getMatricola(){ + return matricola; } public String getNomeCognome(){ return nome.concat(" ").concat(cnome); } - public boolean lookUp(String nome, String cnome){ - if(this.nome.equals(nome) && this.cnome.equals(cnome)) - return true; - return false; + public boolean equals(String nome, String cnome){ + return this.nome.equals(nome) && this.cnome.equals(cnome); } public static Studente read(Scanner sc) throws Exception{ String nome; String cnome; - int mat; - if(sc.hasNext()){ - nome=sc.next(); - if(sc.hasNext()){ - cnome=sc.next(); - if(sc.hasNextInt()){ - mat=sc.nextInt(); - return new Studente(nome, cnome, mat); - } - } - } - return null; + int matricola; + + if(!sc.hasNext()) return null; + nome=sc.next(); + if(!sc.hasNext()) return null; + cnome=sc.next(); + if(!sc.hasNextInt()) return null; + matricola=sc.nextInt(); + + return new Studente(nome, cnome, matricola); + } + + public String toString(){ + return nome + " " + cnome + " " + matricola; + } + + public void print(PrintStream ps){ + ps.println(toString()); } private String nome; private String cnome; - private int mat; + private int matricola; } diff --git a/src/Studenti-Esami/Studenti.dati b/src/Studenti-Esami/Studenti.dati index 2282848..cfbc34a 100644 --- a/src/Studenti-Esami/Studenti.dati +++ b/src/Studenti-Esami/Studenti.dati @@ -1,9 +1,3 @@ -Walter -White -1212 -Jesse -Pinkman -1313 -Gustavo -Fring -1414 +Walter White 1212 +Jesse Pinkman 1313 +Gustavo Fring 1414 diff --git a/src/Studenti-Esami/Test.java b/src/Studenti-Esami/Test.java new file mode 100644 index 0000000..ee01e2c --- /dev/null +++ b/src/Studenti-Esami/Test.java @@ -0,0 +1,27 @@ +import java.io.*; +import java.util.Scanner; + +public class Test{ + public static void main(String [] args) throws Exception{ + Scanner sc = new Scanner(System.in); + PrintStream ps = new PrintStream(System.out); + Segreteria segreteria = new Segreteria("Esami.dati", "Studenti.dati"); + Segreteria filtro; + int matricola, x=20, y=27; + + ps.println("Inserisci il nome e cognome dello studente."); + matricola=segreteria.getMatricola(sc.next(), sc.next()); + + if(matricola==0) + ps.println("Errore"); + else{ + filtro = segreteria.filtroMatricola(matricola); + ps.println("Esami sostenuti dallo studente "); + filtro.print(ps); + } + + filtro = segreteria.filtroMatricola(matricola).filtroMaggioreVoto(x).filtroMinoreVoto(y); + ps.println("Esami con voti compresi tra " + x + " e " + y + " sostenuti dallo studente "); + filtro.print(ps); + } +}