Skip to content

Instantly share code, notes, and snippets.

@JugurthaK
Last active March 29, 2018 05:24
Show Gist options
  • Save JugurthaK/1e68127c5c0e6f0912dec6705f728910 to your computer and use it in GitHub Desktop.
Save JugurthaK/1e68127c5c0e6f0912dec6705f728910 to your computer and use it in GitHub Desktop.
Correction d'une interro en Java
class Personne {
private String nom;
private String prenom;
private int annee;
private int mois;
// Création des constructeurs
public Personne(){
this.nom = "Doe";
this.prenom = "John";
this.annee = 2000;
this.mois = 1;
}
public Personne(Personne p){
this.nom = p.nom;
this.prenom = p.prenom;
this.annee = p.annee;
this.mois = p.mois;
}
public Personne(String n, String p, int a, int m){
this.nom = n;
this.prenom = p;
this.annee = a;
if (m <= 12 && m >= 1){
this.mois = m;
} else {
this.mois = 1;
System.err.println("Mois invalide");
}
}
// Création des getters & setters
public String getNom(){
return this.nom;
}
public void setNom(String n){
this.nom = n;
}
public String getPrenom(){
return this.prenom;
}
public void setPrenom(String p){
this.prenom = p;
}
public int getAnnee(){
return this.annee;
}
public void setAnnee(int n){
this.annee = n;
}
public int getMois(){
return this.mois;
}
public void setMois(int m){
if (m <= 12 && m >= 1){
this.mois = m;
} else {
System.out.println("Mois invalide");
this.mois = 1;
}
}
// Créations des autres méthodes
public String toString(){
return ("Bonjour, je m'appelle "+this.prenom+" "+this.nom+"je suis né en "+this.mois+"/"+this.annee);
}
public boolean equals(Personne p){
return (this.nom == p.nom && this.prenom == p.prenom && this.annee == p.annee && this.mois == p.mois);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment