Correction d’examen National du BTS DSI session Mai 2012  : JAVA 



public abstract class Exam2012 {
        private static int ref=1;
        private static int compteur=1;
        private String Des;
        private double prixAchat;
        protected double prixVente;
       protected int Qte;

    public int getRef() {
        return ref;
    }

    public void setRef(int ref) {
        this.ref = ref;
    }

    public static int getCompteur() {
        return compteur;
    }

    public static void setCompteur(int compteur) {
        Exam2012.compteur = compteur;
    }

    public String getDes() {
        return Des;
    }

    public void setDes(String Des) {
        this.Des = Des;
    }

    public double getPrixAchat() {
        return prixAchat;
    }

    public void setPrixAchat(double prixAchat) {
        this.prixAchat = prixAchat;
    }

    public double getPrixVente() {
        return prixVente;
    }

    public void setPrixVente(double prixVente) {
        this.prixVente = prixVente;
    }

    public int getQte() {
        return Qte;
    }

    public void setQte(int Qte) {
        this.Qte = Qte;
    }

    public Exam2012(String Des, double prixAchat, double prixVente, int Qte) {
        ref++;
        compteur++;
        this.Des = Des;
        this.prixAchat = prixAchat;
        this.prixVente = prixVente;
        this.Qte = Qte;
       
           
                    
    }

    
    public String toString() {
        return "Exam2012{" + "ref=" + ref + ",Compteur="+compteur+", Des=" + Des + ", prixAchat=" + prixAchat + ", prixVente=" + prixVente + ", Qte=" + Qte + '}';
    }
       public abstract double CalPrix(); 
    }
    

 

public class Telev extends Exam2012{
      private int taille;
      private String Couleur;
     private  double  prx;
    public Telev( String Des, double prixAchat, double prixVente, int Qte,int t,String C) {
        super(Des, prixAchat, prixVente, Qte);
        this.taille=t;
        this.Couleur=C;
    }
       

    
    public void setPrixVente(double prixVente) {
        super.setPrixVente(prixVente); 
    }
    public int getTaille() {
        return taille;
    }

    public void setTaille(int taille) {
        this.taille = taille;
    }

    public String getCouleur() {
        return Couleur;
    }

    public void setCouleur(String Couleur) {
        this.Couleur = Couleur;
    }

    @Override
    public String toString() {
        return super.toString()+"Telev{" + "taille=" + taille + ", Couleur=" + Couleur + '}';
    }

     
    public double CalPrix(){
        if(Qte>10){
            double  prx=prixVente*(5/100);
            
        }
        return prx;
           
    }
    
    
}


public class Televesion extends Exam2012{
    private int pauce;
    private String marque;
    public double prix;
    
    public int getPauce() {
        return pauce;
    }

    public void setPauce(int pauce) {
        this.pauce = pauce;
    }

    public String getMarque() {
        return marque;
    }

    public void setMarque(String marque) {
        this.marque = marque;
    }
    

    public Televesion(String Des, double prixAchat, double prixVente, int Qte,int pauce,String marque) {
        super(Des, prixAchat, prixVente, Qte);
        this.pauce=pauce;
        this.marque=marque;
    }

     
    public String toString() {
        return super.toString()+"Televesion{" + "pauce=" + pauce + ", marque=" + marque + '}';
    }

     
    public double CalPrix(){
        if(Qte>5){ 
            prix=prixVente*(10/100);
        }
        return prix;
    }
    
    
}

Test :

public class Test {
    static Exam2012[] tab=new Exam2012[2];
    public static void main(String[] args){
        Televesion t1=new Televesion("des1", 20.00, 225, 25, 14, "LG"); 
       System.out.println(t1.CalPrix());
        tab[0]=new Televesion("des1", 20.00, 225, 25, 14, "LG"); 
         tab[1]=new Telev("des2", 30.33, 125, 47, 100, "Noir");
         for(Exam2012 t:tab){
             System.out.println(t);
             if(t instanceof Televesion)
             System.out.println(t.CalPrix());
             else
                 System.out.println(t.CalPrix()); 
         }
        
    }
    
}












































Commentaires