ok
This commit is contained in:
74
src/fr/iutfbleau/projetIHM2022FI2/MP/EtudiantNP.java
Normal file
74
src/fr/iutfbleau/projetIHM2022FI2/MP/EtudiantNP.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package fr.iutfbleau.projetIHM2022FI2.MP;
|
||||
import fr.iutfbleau.projetIHM2022FI2.API.*;
|
||||
import java.util.*;
|
||||
/**
|
||||
* Un étudiant
|
||||
*/
|
||||
|
||||
public class EtudiantNP implements Etudiant{
|
||||
|
||||
// auto-incrément des étudiants
|
||||
private static int nextId=0;
|
||||
// id de l'étudiant
|
||||
private int id;
|
||||
// nom et prénom de l'étudiant
|
||||
private String nom, prenom;
|
||||
|
||||
/**
|
||||
* Constructeur d'un étudiant.
|
||||
* @param nom le nom de l'étudiant
|
||||
* @param prenom le prénom de l'étudiant
|
||||
*
|
||||
*/
|
||||
public EtudiantNP(String nom, String prenom){
|
||||
Objects.requireNonNull(nom,"On ne peut pas créer un étudiant avec un nom null");
|
||||
Objects.requireNonNull(prenom,"On ne peut pas créer un étudiant avec un nom null");
|
||||
// auto incrément de l'id
|
||||
this.id=++this.nextId;
|
||||
this.nom=nom;
|
||||
this.prenom=prenom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructeur d'un étudiant.
|
||||
* @param nom le nom de l'étudiant
|
||||
* @param prenom le prénom de l'étudiant
|
||||
* @param id l'id de l'étudiant
|
||||
*/
|
||||
public EtudiantNP(String nom, String prenom, int id){
|
||||
Objects.requireNonNull(nom,"On ne peut pas créer un étudiant avec un nom null");
|
||||
Objects.requireNonNull(prenom,"On ne peut pas créer un étudiant avec un nom null");
|
||||
if(id>=this.nextId){
|
||||
this.nextId=id;
|
||||
}
|
||||
this.id=id;
|
||||
this.nom=nom;
|
||||
this.prenom=prenom;
|
||||
}
|
||||
|
||||
/**
|
||||
* permet de récupérer l'identifiant de l'étudiant.
|
||||
* @return l'identifiant.
|
||||
*/
|
||||
public int getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* permet de récupérer
|
||||
* @return le nom de l'étudiant.
|
||||
*/
|
||||
public String getNom(){
|
||||
return this.nom;
|
||||
}
|
||||
|
||||
/**
|
||||
* permet de récupérer
|
||||
* @return le prénom de l'étudiant
|
||||
*/
|
||||
public String getPrenom(){
|
||||
return this.prenom;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user