TD3 ex2 ok
This commit is contained in:
parent
8d05cc28a2
commit
29082acd3e
@ -1,33 +1,37 @@
|
|||||||
package TD3.fleuriste;
|
package TD3.fleuriste;
|
||||||
|
|
||||||
public class Bouquet {
|
public class Bouquet {
|
||||||
private LotFleurs lot1;
|
private LotFleur lot0;
|
||||||
private LotFleurs lot2;
|
private LotFleur lot1;
|
||||||
private LotFleurs lot3;
|
private LotFleur lot2;
|
||||||
|
|
||||||
public Bouquet(LotFleurs un, LotFleurs deux, LotFleurs trois) {
|
public Bouquet(LotFleur un, LotFleur deux, LotFleur trois) {
|
||||||
if (un.fleur.getNom() == deux.fleur.getNom() || un.fleur.getNom() == trois.fleur.getNom() || deux.fleur.getNom() == trois.fleur.getNom())
|
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");
|
throw new RuntimeException("Même fleurs");
|
||||||
lot1 = un;
|
this.lot0 = un;
|
||||||
lot2 = deux;
|
this.lot1 = deux;
|
||||||
lot3 = trois;
|
this.lot2 = trois;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double prix() {
|
public double prix() {
|
||||||
double prix = lot1.fleur.prix*lot1.nombre+lot2.fleur.prix*lot2.nombre+lot3.fleur.prix*lot3.nombre;
|
return (lot0.getPrix() + lot1.getPrix() + lot2.getPrix());
|
||||||
return prix += prix*15/100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LotFleurs getLot1() {
|
public LotFleur getLot0() {
|
||||||
return lot1;
|
return this.lot0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LotFleur getLot1() {
|
||||||
|
return this.lot1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LotFleurs getLot2() {
|
public LotFleur getLot2() {
|
||||||
return lot2;
|
return this.lot2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LotFleurs getLot3() {
|
@Override
|
||||||
return lot3;
|
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;
|
package TD3.fleuriste;
|
||||||
|
|
||||||
public class Fleur {
|
public class Fleur {
|
||||||
String nom;
|
private String nom;
|
||||||
double prix;
|
private double prix;
|
||||||
|
|
||||||
public Fleur(String nomf, double prix) {
|
public Fleur(String n, double p) {
|
||||||
this.nom = nomf;
|
this.nom = n;
|
||||||
this.prix = prix;
|
this.prix = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fleur clone() {
|
@Override
|
||||||
return (new Fleur(this.nom, this.prix));
|
protected Object clone() throws CloneNotSupportedException {
|
||||||
|
return new Fleur(this.nom, this.prix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNom() {
|
public String getNom() {
|
||||||
return this.nom;
|
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 int quantite;
|
||||||
private Fleur Fleur;
|
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) {
|
public LotFleur(Fleur nomFleur, int quantiteFleur) {
|
||||||
this.quantite = quantiteFleur;
|
this.quantite = quantiteFleur;
|
||||||
this.setFleur(nomFleur);
|
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;
|
package TD3.fleuriste;
|
||||||
|
|
||||||
public class Stock {
|
public class Stock {
|
||||||
Fleur roses;
|
|
||||||
Fleur tulipes;
|
//roses = 0, tulipes = 1, œillets = 2
|
||||||
Fleur oeillet;
|
|
||||||
int nbr;
|
private Fleur[] fleurs = new Fleur[3];
|
||||||
int nbt;
|
private int quantite[] = {0, 0, 0};
|
||||||
int nbo;
|
|
||||||
|
public Stock() {
|
||||||
|
this(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public Stock(Fleur r, Fleur t, Fleur o) {
|
public Stock(Fleur r, Fleur t, Fleur o) {
|
||||||
roses = r;
|
this.fleurs[0] = r;
|
||||||
tulipes = t;
|
this.fleurs[1] = t;
|
||||||
oeillet = o;
|
this.fleurs[2] = o;
|
||||||
nbr = 0;
|
|
||||||
nbt = 0;
|
|
||||||
nbo = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ajouteRose(int nb) {
|
public void ajouteFleur(Fleur f, int q) {
|
||||||
nbr += nb;
|
switch (f.getNom().toLowerCase()) {
|
||||||
}
|
case "rose":
|
||||||
|
this.setQuantite(0, this.getFleurQuantity(f.getNom()) + q);
|
||||||
public void ajouteOeillet(int nb) {
|
break;
|
||||||
nbo = nb;
|
case "tulipe":
|
||||||
}
|
this.setQuantite(1, this.getFleurQuantity(f.getNom()) + q);
|
||||||
|
break;
|
||||||
public void ajouteTulipe(int nb) {
|
case "oeillet":
|
||||||
nbt = nb;
|
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) {
|
public boolean bouquetFaisable(Bouquet b) {
|
||||||
boolean faisable = true;
|
return (this.quantite[0] > b.getLot0().getQuantite() || this.quantite[1] > b.getLot1().getQuantite() || this.quantite[2] > b.getLot2().getQuantite());
|
||||||
if (b.getLot1().nombre > nbr || b.getLot2().nombre > nbt || b.getLot3().nombre > nbo) {
|
|
||||||
faisable = false;
|
|
||||||
}
|
|
||||||
return faisable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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