Comment mettre des paramètres optionnels dans un constructeur? Urgenttttt

lordskyser1 Messages postés 84 Date d'inscription lundi 31 mars 2003 Statut Membre Dernière intervention 1 juillet 2006 - 29 nov. 2005 à 18:42
lordskyser1 Messages postés 84 Date d'inscription lundi 31 mars 2003 Statut Membre Dernière intervention 1 juillet 2006 - 1 déc. 2005 à 21:54
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

4 réponses

cs_ducheseb Messages postés 344 Date d'inscription mardi 18 mai 2004 Statut Membre Dernière intervention 23 juin 2006 9
29 nov. 2005 à 18:50
Tu ne peux pas mettre de paramètres optionnel en Java :)

"A game is a series of interesting choices." Sid Meier
0