This commit is contained in:
Orange_Dugongo 2016-10-20 17:19:43 +02:00
parent 5de9883c8c
commit aba69b19bf
8 changed files with 150 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,41 @@
import java.util.Scanner;
public class Esame{
public Esame(String nome, int voto, int mat){
this.nome=nome;
this.voto=voto;
this.mat=mat;
}
public int getVoto(){
return voto;
}
public Esame lookUp(int mat){
if(this.mat==mat)
return this;
return null;
}
public static Esame read(Scanner sc) throws Exception{
String nome;
int voto;
int mat;
if(sc.hasNext()){
nome=sc.nextLine();
if(sc.hasNext()){
voto=sc.nextInt();
if(sc.hasNext()){
mat=sc.nextInt();
return new Esame(nome, voto, mat);
}
}
}
return null;
}
private String nome;
private int voto;
private int mat;
}

View File

@ -0,0 +1,12 @@
Chimica
30
1212
Chimica
18
1313
Economia
25
1212
Economia
30
1414

Binary file not shown.

View File

@ -0,0 +1,43 @@
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;
boolean trovato = false;
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 && !trovato){
s=s.lookUp(nome, cnome);
if(s!=null){
trovato=true;
sc=new Scanner(srcEsami);
e=Esame.read(sc);
while(e!=null){
e=e.lookUp(s.getMat());
if(e!=null){
media+=e.getVoto();
i++;
}
e=Esame.read(sc);
}
}
s=Studente.read(sc);
}
System.out.println("lo studente "+s.getNomeCognome()+"ha la media di: "+media/i);
}
}

Binary file not shown.

View File

@ -0,0 +1,45 @@
import java.util.Scanner;
public class Studente{
public Studente(String nome, String cnome, int mat){
this.nome=nome;
this.cnome=cnome;
this.mat=mat;
}
public int getMat(){
return mat;
}
public String getNomeCognome(){
return nome.concat(" ").concat(cnome);
}
public Studente lookUp(String nome, String cnome){
if(this.nome.equals(nome) && this.cnome.equals(cnome))
return this;
return null;
}
public static Studente read(Scanner sc) throws Exception{
String nome;
String cnome;
int mat;
if(sc.hasNext()){
nome=sc.nextLine();
if(sc.hasNext()){
cnome=sc.nextLine();
if(sc.hasNext()){
mat=sc.nextInt();
return new Studente(nome, cnome, mat);
}
}
}
return null;
}
private String nome;
private String cnome;
private int mat;
}

View File

@ -0,0 +1,9 @@
Walter
White
1212
Jesse
Pinkman
1313
Gustavo
Fring
1414