Gli scanner leggono solo il primo elemento

This commit is contained in:
Orange_Dugongo 2016-10-21 13:42:23 +02:00
parent dcf8057269
commit 3f0a55026c
7 changed files with 30 additions and 23 deletions

Binary file not shown.

View File

@ -12,21 +12,29 @@ public class Esame{
return voto;
}
public Esame lookUp(int mat){
public int getMat(){
return mat;
}
public String getNome(){
return nome;
}
public boolean lookUp(int mat){
if(this.mat==mat)
return this;
return null;
return true;
return false;
}
public static Esame read(Scanner sc) throws Exception{
String nome;
int voto;
int mat;
if(sc.hasNext()){
if(sc.hasNextLine()){
nome=sc.nextLine();
if(sc.hasNext()){
if(sc.hasNextInt()){
voto=sc.nextInt();
if(sc.hasNext()){
if(sc.hasNextInt()){
mat=sc.nextInt();
return new Esame(nome, voto, mat);
}

View File

@ -1,7 +1,4 @@
Chimica
30
1212
Chimica
18
1313
Economia
@ -10,3 +7,6 @@ Economia
Economia
30
1414
Chimica
30
1212

Binary file not shown.

View File

@ -9,7 +9,6 @@ public class Main{
Esame e;
Studente s;
int i=0;
boolean trovato = false;
double media=0;
String nome, cnome;
@ -20,20 +19,20 @@ public class Main{
sc=new Scanner(srcStudenti);
s=Studente.read(sc);
while(s!=null && !trovato){
s=s.lookUp(nome, cnome);
if(s!=null){
trovato=true;
while(s!=null){
if(s.lookUp(nome, cnome)){
sc=new Scanner(srcEsami);
e=Esame.read(sc);
while(e!=null){
e=e.lookUp(s.getMat());
if(e!=null){
System.out.println(e.getVoto()+" "+e.getMat()+" "+e.getNome());
if(e.lookUp(s.getMat())){
System.out.println("ok "+e.getVoto());
media+=e.getVoto();
i++;
}
e=Esame.read(sc);
}
break;
}
s=Studente.read(sc);
}

Binary file not shown.

View File

@ -16,21 +16,21 @@ public class Studente{
return nome.concat(" ").concat(cnome);
}
public Studente lookUp(String nome, String cnome){
public boolean lookUp(String nome, String cnome){
if(this.nome.equals(nome) && this.cnome.equals(cnome))
return this;
return null;
return true;
return false;
}
public static Studente read(Scanner sc) throws Exception{
String nome;
String cnome;
int mat;
if(sc.hasNext()){
if(sc.hasNextLine()){
nome=sc.nextLine();
if(sc.hasNext()){
if(sc.hasNextLine()){
cnome=sc.nextLine();
if(sc.hasNext()){
if(sc.hasNextInt()){
mat=sc.nextInt();
return new Studente(nome, cnome, mat);
}