fin TD3
This commit is contained in:
36
TD3/fleuriste/Bouquet.cs
Normal file
36
TD3/fleuriste/Bouquet.cs
Normal file
@ -0,0 +1,36 @@
|
||||
namespace Programmation_objet_TLESIO21.TD3.fleuriste {
|
||||
|
||||
|
||||
public class Bouquet {
|
||||
private LotFleur lot0;
|
||||
private LotFleur lot1;
|
||||
private LotFleur lot2;
|
||||
|
||||
public Bouquet(LotFleur un, LotFleur deux, LotFleur trois) {
|
||||
this.lot0 = un;
|
||||
this.lot1 = deux;
|
||||
this.lot2 = trois;
|
||||
}
|
||||
|
||||
public double Prix() {
|
||||
return (lot0.GetPrix() + lot1.GetPrix() + lot2.GetPrix());
|
||||
}
|
||||
|
||||
public LotFleur GetLot0() {
|
||||
return this.lot0;
|
||||
}
|
||||
|
||||
public LotFleur GetLot1() {
|
||||
return this.lot1;
|
||||
}
|
||||
|
||||
public LotFleur GetLot2() {
|
||||
return this.lot2;
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "Le bouquet est composé de " + lot0.GetQuantite() + " " + lot0.GetFleur().GetNom() + "s, " + lot1.GetQuantite() + " " + lot1.GetFleur().GetNom() + "s et " + lot2.GetQuantite() + " " + lot2.GetFleur().GetNom() + ". " + lot0.ToString() + " " + lot1.ToString() + " " + lot2.ToString() + ". Le bouquet a donc un prix de " + this.Prix() + "€.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
TD3/fleuriste/Fleur.cs
Normal file
31
TD3/fleuriste/Fleur.cs
Normal file
@ -0,0 +1,31 @@
|
||||
namespace Programmation_objet_TLESIO21.TD3.fleuriste {
|
||||
|
||||
|
||||
public class Fleur {
|
||||
private String nom;
|
||||
private double prix;
|
||||
|
||||
public Fleur(String n, double p) {
|
||||
this.nom = n;
|
||||
this.prix = p;
|
||||
}
|
||||
|
||||
protected Object Clone() {
|
||||
return new Fleur(this.nom, this.prix);
|
||||
}
|
||||
|
||||
public String GetNom() {
|
||||
return this.nom;
|
||||
}
|
||||
|
||||
public double GetPrix() {
|
||||
return prix;
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "1 " + this.GetNom() + " a un prix unitaire de " + this.GetPrix() + "euros.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
40
TD3/fleuriste/LotFleur.cs
Normal file
40
TD3/fleuriste/LotFleur.cs
Normal file
@ -0,0 +1,40 @@
|
||||
namespace Programmation_objet_TLESIO21.TD3.fleuriste {
|
||||
|
||||
|
||||
public class LotFleur {
|
||||
|
||||
private int quantite;
|
||||
private Fleur Fleur;
|
||||
|
||||
public LotFleur(Fleur nomFleur, int quantiteFleur) {
|
||||
this.quantite = quantiteFleur;
|
||||
this.Fleur = nomFleur;
|
||||
}
|
||||
|
||||
public int GetQuantite() {
|
||||
return quantite;
|
||||
}
|
||||
|
||||
public Fleur GetFleur() {
|
||||
return Fleur;
|
||||
}
|
||||
|
||||
public double GetPrix() {
|
||||
return this.GetFleur().GetPrix() * this.GetQuantite();
|
||||
}
|
||||
|
||||
public void SetQuantite(int quantite) {
|
||||
this.quantite = quantite;
|
||||
}
|
||||
|
||||
public void SetFleur(Fleur fleur) {
|
||||
Fleur = fleur;
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return this.GetFleur().ToString() + " Le lot de " + this.GetQuantite() + " " + this.GetFleur().GetNom() + "s coute donc " + this.GetPrix() + "€.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
81
TD3/fleuriste/Stock.cs
Normal file
81
TD3/fleuriste/Stock.cs
Normal file
@ -0,0 +1,81 @@
|
||||
namespace Programmation_objet_TLESIO21.TD3.fleuriste {
|
||||
|
||||
|
||||
public class Stock {
|
||||
|
||||
//roses = 0, tulipes = 1, œillets = 2
|
||||
|
||||
private Fleur[] fleurs = new Fleur[3];
|
||||
private int[] quantite = { 0, 0, 0 };
|
||||
|
||||
public Stock(Fleur r, Fleur t, Fleur o) {
|
||||
this.fleurs[0] = r;
|
||||
this.fleurs[1] = t;
|
||||
this.fleurs[2] = o;
|
||||
}
|
||||
|
||||
public void AjouteFleur(Fleur f, int q) {
|
||||
switch (f.GetNom().ToLower()) {
|
||||
case "rose":
|
||||
this.SetQuantite(0, this.GetFleurQuantity(f.GetNom()) + q);
|
||||
break;
|
||||
case "tulipe":
|
||||
this.SetQuantite(1, this.GetFleurQuantity(f.GetNom()) + q);
|
||||
break;
|
||||
case "oeillet":
|
||||
this.SetQuantite(2, this.GetFleurQuantity(f.GetNom()) + q);
|
||||
break;
|
||||
default:
|
||||
Console.Error.WriteLine("Aucune fleur n'a été ajoutée");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean BouquetFaisable(Bouquet b) {
|
||||
return (this.quantite[0] > b.GetLot0().GetQuantite() || this.quantite[1] > b.GetLot1().GetQuantite() || this.quantite[2] > b.GetLot2().GetQuantite());
|
||||
}
|
||||
public override String ToString() {
|
||||
return "Il y a en stock " + this.GetFleurQuantity("rose") + " roses, " + this.GetFleurQuantity("tulipe") + " tulipes et " + this.GetFleurQuantity("oeillet") + " oeillets. ";
|
||||
}
|
||||
|
||||
public int GetFleurQuantity(String s) {
|
||||
switch (s.ToLower()) {
|
||||
case "rose":
|
||||
return this.GetQuantite(0);
|
||||
case "tulipe":
|
||||
return this.GetQuantite(1);
|
||||
case "oeillet":
|
||||
return this.GetQuantite(2);
|
||||
default:
|
||||
Console.Error.WriteLine("Aucune fleur n'a été ajoutée");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFleurQuantity(String f, int q) {
|
||||
switch (f.ToLower()) {
|
||||
case "rose":
|
||||
this.SetQuantite(0, q);
|
||||
break;
|
||||
case "tulipe":
|
||||
this.SetQuantite(1, q);
|
||||
break;
|
||||
case "oeillet":
|
||||
this.SetQuantite(2, q);
|
||||
break;
|
||||
default:
|
||||
Console.Error.WriteLine("Aucune fleur n'a été ajoutée");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetQuantite(int index, int i) {
|
||||
this.quantite[index] = i;
|
||||
}
|
||||
|
||||
private int GetQuantite(int i) {
|
||||
return this.quantite[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
26
TD3/fleuriste/TestBouquet.cs
Normal file
26
TD3/fleuriste/TestBouquet.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Programmation_objet_TLESIO21.TD3.fleuriste;
|
||||
|
||||
public static class TestBouquet {
|
||||
public static void Exo2() {
|
||||
Fleur rose = new Fleur("rose",2.6);
|
||||
Fleur tulipe = new Fleur("tulipe",0.4);
|
||||
Fleur oeillet = new Fleur("oeillet",1.8);
|
||||
|
||||
LotFleur lotroses = new LotFleur(rose,5);
|
||||
LotFleur lottulipes = new LotFleur(tulipe,7);
|
||||
LotFleur lotoeillets = new LotFleur(oeillet,3);
|
||||
|
||||
Bouquet b = new Bouquet(lotroses, lottulipes, lotoeillets);
|
||||
Console.WriteLine(b.ToString());
|
||||
|
||||
Stock magasin = new Stock(rose,tulipe,oeillet);
|
||||
Console.WriteLine(magasin.ToString());
|
||||
magasin.AjouteFleur(rose, 100);
|
||||
magasin.AjouteFleur(tulipe, 150);
|
||||
magasin.AjouteFleur(oeillet, 200);
|
||||
Console.WriteLine(magasin.ToString());
|
||||
// Est-ce que le stock permet de produire le bouquet b ?
|
||||
Boolean orderBouquet = magasin.BouquetFaisable(b);
|
||||
Console.WriteLine("Est-ce que le stock permet de produire le bouquet ? " + orderBouquet);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user