programmazione-java/src/Studenti-Esami/Studente.java

51 lines
1.1 KiB
Java
Raw Permalink Normal View History

2016-10-20 15:19:43 +00:00
import java.util.Scanner;
2016-10-26 16:11:51 +00:00
import java.io.PrintStream;
2016-10-20 15:19:43 +00:00
public class Studente{
2016-10-26 16:11:51 +00:00
public Studente(String nome, String cnome, int matricola){
2016-10-20 15:19:43 +00:00
this.nome=nome;
this.cnome=cnome;
2016-10-26 16:11:51 +00:00
this.matricola=matricola;
2016-10-20 15:19:43 +00:00
}
2016-10-26 16:11:51 +00:00
public int getMatricola(){
return matricola;
2016-10-20 15:19:43 +00:00
}
public String getNomeCognome(){
return nome.concat(" ").concat(cnome);
}
2016-10-26 16:11:51 +00:00
public boolean equals(String nome, String cnome){
return this.nome.equals(nome) && this.cnome.equals(cnome);
2016-10-20 15:19:43 +00:00
}
public static Studente read(Scanner sc) throws Exception{
String nome;
String cnome;
2016-10-26 16:11:51 +00:00
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());
2016-10-20 15:19:43 +00:00
}
private String nome;
private String cnome;
2016-10-26 16:11:51 +00:00
private int matricola;
2016-10-20 15:19:43 +00:00
}