TD3 ex2 ok
This commit is contained in:
parent
8d05cc28a2
commit
29082acd3e
@ -1,33 +1,37 @@
|
||||
package TD3.fleuriste;
|
||||
|
||||
public class Bouquet {
|
||||
private LotFleurs lot1;
|
||||
private LotFleurs lot2;
|
||||
private LotFleurs lot3;
|
||||
private LotFleur lot0;
|
||||
private LotFleur lot1;
|
||||
private LotFleur lot2;
|
||||
|
||||
public Bouquet(LotFleurs un, LotFleurs deux, LotFleurs trois) {
|
||||
if (un.fleur.getNom() == deux.fleur.getNom() || un.fleur.getNom() == trois.fleur.getNom() || deux.fleur.getNom() == trois.fleur.getNom())
|
||||
public Bouquet(LotFleur un, LotFleur deux, LotFleur trois) {
|
||||
if (un.getFleur().getNom() == deux.getFleur().getNom() || un.getFleur().getNom() == trois.getFleur().getNom() || deux.getFleur().getNom() == trois.getFleur().getNom())
|
||||
throw new RuntimeException("Même fleurs");
|
||||
lot1 = un;
|
||||
lot2 = deux;
|
||||
lot3 = trois;
|
||||
this.lot0 = un;
|
||||
this.lot1 = deux;
|
||||
this.lot2 = trois;
|
||||
}
|
||||
|
||||
public double prix() {
|
||||
double prix = lot1.fleur.prix*lot1.nombre+lot2.fleur.prix*lot2.nombre+lot3.fleur.prix*lot3.nombre;
|
||||
return prix += prix*15/100;
|
||||
return (lot0.getPrix() + lot1.getPrix() + lot2.getPrix());
|
||||
}
|
||||
|
||||
public LotFleurs getLot1() {
|
||||
return lot1;
|
||||
public LotFleur getLot0() {
|
||||
return this.lot0;
|
||||
}
|
||||
|
||||
public LotFleurs getLot2() {
|
||||
return lot2;
|
||||
public LotFleur getLot1() {
|
||||
return this.lot1;
|
||||
}
|
||||
|
||||
public LotFleurs getLot3() {
|
||||
return lot3;
|
||||
public LotFleur getLot2() {
|
||||
return this.lot2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,30 @@
|
||||
package TD3.fleuriste;
|
||||
|
||||
public class Fleur {
|
||||
String nom;
|
||||
double prix;
|
||||
private String nom;
|
||||
private double prix;
|
||||
|
||||
public Fleur(String nomf, double prix) {
|
||||
this.nom = nomf;
|
||||
this.prix = prix;
|
||||
public Fleur(String n, double p) {
|
||||
this.nom = n;
|
||||
this.prix = p;
|
||||
}
|
||||
|
||||
public Fleur clone() {
|
||||
return (new Fleur(this.nom, this.prix));
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return new Fleur(this.nom, this.prix);
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return this.nom;
|
||||
}
|
||||
|
||||
public double getPrix() {
|
||||
return prix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "1 " + this.getNom() + " a un prix unitaire de " + this.getPrix() + "€.";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,32 +5,35 @@ public class LotFleur {
|
||||
private int quantite;
|
||||
private Fleur Fleur;
|
||||
|
||||
//getters
|
||||
public int getQuantite() {
|
||||
return quantite;
|
||||
}
|
||||
|
||||
public Fleur getFleur() {
|
||||
return Fleur;
|
||||
}
|
||||
|
||||
//setters
|
||||
public void setQuantite(int quantite) {
|
||||
this.quantite = quantite;
|
||||
}
|
||||
|
||||
public void setFleur(Fleur fleur) {
|
||||
Fleur = fleur;
|
||||
}
|
||||
|
||||
//instructions
|
||||
public LotFleur(Fleur nomFleur, int quantiteFleur) {
|
||||
this.quantite = quantiteFleur;
|
||||
this.setFleur(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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getFleur().toString() + " Le lot de " + this.getQuantite() + " " + this.getFleur().getNom() + "s coute donc " + this.getPrix() + "€.";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,39 +1,85 @@
|
||||
package TD3.fleuriste;
|
||||
|
||||
public class Stock {
|
||||
Fleur roses;
|
||||
Fleur tulipes;
|
||||
Fleur oeillet;
|
||||
int nbr;
|
||||
int nbt;
|
||||
int nbo;
|
||||
|
||||
//roses = 0, tulipes = 1, œillets = 2
|
||||
|
||||
private Fleur[] fleurs = new Fleur[3];
|
||||
private int quantite[] = {0, 0, 0};
|
||||
|
||||
public Stock() {
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
public Stock(Fleur r, Fleur t, Fleur o) {
|
||||
roses = r;
|
||||
tulipes = t;
|
||||
oeillet = o;
|
||||
nbr = 0;
|
||||
nbt = 0;
|
||||
nbo = 0;
|
||||
this.fleurs[0] = r;
|
||||
this.fleurs[1] = t;
|
||||
this.fleurs[2] = o;
|
||||
}
|
||||
|
||||
public void ajouteRose(int nb) {
|
||||
nbr += nb;
|
||||
}
|
||||
|
||||
public void ajouteOeillet(int nb) {
|
||||
nbo = nb;
|
||||
}
|
||||
|
||||
public void ajouteTulipe(int nb) {
|
||||
nbt = nb;
|
||||
public void ajouteFleur(Fleur f, int q) {
|
||||
switch (f.getNom().toLowerCase()) {
|
||||
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:
|
||||
System.err.println("Aucune fleur n'a été ajoutée");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean bouquetFaisable(Bouquet b) {
|
||||
boolean faisable = true;
|
||||
if (b.getLot1().nombre > nbr || b.getLot2().nombre > nbt || b.getLot3().nombre > nbo) {
|
||||
faisable = false;
|
||||
}
|
||||
return faisable;
|
||||
return (this.quantite[0] > b.getLot0().getQuantite() || this.quantite[1] > b.getLot1().getQuantite() || this.quantite[2] > b.getLot2().getQuantite());
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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.toLowerCase()) {
|
||||
case "rose":
|
||||
return this.getQuantite(0);
|
||||
case "tulipe":
|
||||
return this.getQuantite(1);
|
||||
case "oeillet":
|
||||
return this.getQuantite(2);
|
||||
default:
|
||||
System.err.println("Aucune fleur n'a été ajoutée");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFleurQuantity(String f, int q) {
|
||||
switch (f.toLowerCase()) {
|
||||
case "rose":
|
||||
this.setQuantite(0, q);
|
||||
break;
|
||||
case "tulipe":
|
||||
this.setQuantite(1, q);
|
||||
break;
|
||||
case "oeillet":
|
||||
this.setQuantite(2, q);
|
||||
break;
|
||||
default:
|
||||
System.err.println("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];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user