Correction TP5 POO (en langage java)
//class HabitationProfessionelle*************************
package pkg2014tp5;
public class HabitationProfessionelle extends Habitation {
private int NbEmployes;
public HabitationProfessionelle() {
}
public HabitationProfessionelle(int NbEmployes, String proprietaire, String adresse, double surface) {
super(proprietaire, adresse, surface);
this.NbEmployes = NbEmployes;
}
public int getNbEmployes() {
return NbEmployes;
}
public void setNbEmployes(int NbEmployes) {
this.NbEmployes = NbEmployes;
}
public double impot(){
return super.impot()+(NbEmployes/10+1)*1000;
}
public void affiche(){
super.affiche();
System.out.println(" ,le nombre d'employes :"+ NbEmployes);
}
}
//class Principale ***********************
package pkg2014tp5;
public class Main {
public static void main(String[] args) {
HabitationIndividuelle hi1 = new HabitationIndividuelle(7,true,"abdellah"," hay el kods
laayoune",230);
Habitation hi2 = new HabitationIndividuelle(5,false,"samir"," hay el fath laayoune",230);
Habitation hp = new HabitationProfessionelle(27,"hanane"," hay el kassam laayoune",230);
Habitation tab []= new Habitation[7];
tab[0]=hi1;
tab[1]=hi2;
tab[2]=hp;
for(int i=0;i<3;i++)
{
tab[i].affiche();
System.out.println(" l'impot de "+tab[i].getProprietaire()+ " est : "+ tab[i].impot() + " DH");
}
}
}