Bonjour,
j'ai une classe Personne et je voudrais mettre des paramètres optionnels dans le constructeur pour eviter d'avoir à en faire 50000. Voici ma classe :
public abstract class Personne{
// Attributs
private String nom;
private String prenom;
private String adresse;
private String cp;
private String ville;
private String email;
private String url;
private String telFixe;
// CONSTRUCTEURS
// Constructeur par défaut
public Personne(){
this.nom = "";
this.prenom = "";
this.adresse = "";
this.cp = "";
this.ville = "";
this.email = "";
this.url = "";
this.telFixe = "";
}
// Constructeur 1
public Personne(String nom, String prenom, String adresse,
String cp, String ville){
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
this.cp = cp;
this.ville = ville;
}
// Constructeur 2
public Personne(String nom, String prenom, String adresse,
String cp, String ville, String email, String url,
String telFixe){
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
this.cp = cp;
this.ville = ville;
this.email = email;
this.url ="";
this.telFixe = telFixe;
}
// Constructeur 2
public Personne(String nom, String prenom, String adresse,
String cp, String ville, String email, String url,
String telFixe){
this.nom = nom;
this.prenom = prenom;
this.adresse = adresse;
this.cp = cp;
this.ville = ville;
this.email = email;
this.url ="";
this.telFixe = telFixe;
}
// accesseurs
public String getNom(){
return this.nom;
}
public void setNom(String nom){
this.nom = nom;
}
public String getPrenom(){
return this.prenom;
}
public void setPrenom(String prenom){
this.prenom = prenom;
}
public String getAdresse(){
return this.adresse;
}
public void setAdresse(String adresse){
this.adresse = adresse;
}
public String getCP(){
return this.cp;
}
public void setCP(String cp){
this.cp = cp;
}
public String getVille(){
return this.ville;
}
public void setVille(String ville){
this.ville = ville;
}
public String getEmail(){
return this.email;
}
public void setEmail(String email){
this.email = email;
}
public String getUrl(){
return this.url;
}
public void setUrl(String url){
this.url = url;
}
public String getTelFixe(){
return this.telFixe;
}
public void setTelFixe(String telFixe){
this.telFixe = telFixe;
}
// Méthodes
public String toString(){
return "\nNom : " + this.getNom()
+ "\nPrenom : " + this.getPrenom()
+ "\nAdresse : " + this.getAdresse() + " " + this.getCP()
+ "\nTelephone : " + this.getTelFixe() + "\n";
}
}
Les paramètres otpionnels seraient String email, String url, String telFixe.
Si vous savez ce serait vraiment sympa de m'éclairer car je dois rendre un projet jeudi et là je bloque la dessus! alala les débuts en java, pas toujours simples!
Merci bonne soirée, au revoir
