1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| public class Adresse {
private String adresse1;
private String adresse2;
private String cp;
private String ville;
private Pays pays;
public Adresse(String adresse1, String adresse2, String cp, String ville,
Pays pays) throws Exception {
super();
this.setAdresse1(adresse1);
this.setAdresse2(adresse2);
this.setCp(cp);
this.setPays(pays);
this.setVille(ville);
}
public String getAdresse1() {
return adresse1;
}
public void setAdresse1(String adresse1) {
this.adresse1 = adresse1;
}
public String getAdresse2() {
return adresse2;
}
public void setAdresse2(String adresse2) {
this.adresse2 = adresse2;
}
public String getCp() {
return cp;
}
public void setCp(String cp) throws Exception {
if (!cp.matches("((0[1-9])|([1-9][0-9]))[0-9]{3}+")) {
throw new Exception("Le format du code postal n'est pas valide");
}
this.cp = cp;
}
public Pays getPays() {
return pays;
}
public void setPays(Pays pays) {
this.pays = pays;
}
public String getVille() {
return ville;
}
public void setVille(String ville) throws Exception {
if (!ville.matches("[^0-9]*")) {
throw new Exception("Le format de la ville n'est pas valide");
}
this.ville = ville;
}
public void affiche(){
System.out.println("\nAdresse 1 : "+this.getAdresse1()+"\nAdresse 2 : "+this.getAdresse2()+"\nCode postal : "+this.getCp()+"\nVille : "+this.getVille()+"\nPays : "+this.getPays().getLibelle());
}
} // end Adresse |
Partager