Advertisement
mmouhib

heritage ex3

Nov 22nd, 2021
1,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. public class Materiel {
  2.     private String ref;
  3.     private int quantite;
  4.     private float achat;
  5.     protected float prixVente;
  6.     private Fournisseur leFournisseur;
  7.  
  8.     public Materiel(String r, float pa){
  9.         ref = r;
  10.         achat = pa;
  11.     }
  12.  
  13.     public void livrer(float q){
  14.         quantite -= q;
  15.     }
  16.  
  17.     public void stoquer(float q){
  18.         quantite += q;
  19.     }
  20.  
  21.     public void fournir(Fournisseur f){
  22.         leFournisseur = f;
  23.     }
  24.  
  25.     public void afficher(){
  26.         String newLine = "\n";
  27.         System.out.println(ref + newLine + quantite + newLine +
  28.                 achat + newLine + prixVente + newLine + leFournisseur);
  29.     }
  30.  
  31.     @Override
  32.     public String toString(){
  33.         String newLine = "\n";
  34.         return (ref + newLine + quantite + newLine +
  35.                 achat + newLine + prixVente + newLine + leFournisseur);
  36.     }
  37.  
  38. }
  39.  
  40.  
  41.  
  42. public class MaterielEnPromotion extends Materiel {
  43.  
  44.     private String typeDePromo;
  45.     private int pourcentageReduction;
  46.  
  47.     public MaterielEnPromotion(String r, float pa, String type, int pourcentage) {
  48.         super(r, pa);
  49.         typeDePromo = type;
  50.         pourcentageReduction = pourcentage;
  51.     }
  52.  
  53.     @Override
  54.     public String toString(){
  55.         String newLine = "\n";
  56.         return(super.toString() + typeDePromo + newLine + pourcentageReduction);
  57.     }
  58.  
  59.  
  60. }
  61.  
  62.  
  63. public class Fournisseur {
  64.     private String nom, adresse;
  65.  
  66.     public Fournisseur(String nom, String adr){
  67.         this.nom = nom;
  68.         adresse = adr;
  69.     }
  70.  
  71.     public String getNom() {
  72.         return nom;
  73.     }
  74.  
  75.     public String getAdresse() {
  76.         return adresse;
  77.     }
  78.  
  79.     @Override
  80.     public String toString(){
  81.         String newLine = "\n";
  82.         return(nom + newLine + adresse);
  83.     }
  84.  
  85.  
  86. }
  87.  
  88. public class Main {
  89.     public static void main(String[] args) {
  90.         Fournisseur fourn = new Fournisseur("scoop", "Ezzahra");
  91.         MaterielEnPromotion mat = new MaterielEnPromotion("Mac M1", 1000F, "Remise a la caisse", 30);
  92.         mat.prixVente = 1300;
  93.         mat.fournir(fourn);
  94.         System.out.println(mat);
  95.     }
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement