Commit 46d9a61d authored by Antoine Hazebrouck's avatar Antoine Hazebrouck

refactor ingredients

parent fa03581c
......@@ -3,6 +3,7 @@ package imt;
import imt.ingredients.Consigne;
import imt.ingredients.Ingredient;
import imt.ingredients.Legume;
import imt.ingredients.Plat;
import imt.ingredients.ViandePoisson;
public class Application {
......
package imt.ingredients;
public class Autre extends Ingredient {
private int calories;
private boolean bio;
public Autre(int idIngredient, String nomIngredient, int calories, boolean bio) {
super(idIngredient, nomIngredient);
this.calories = calories;
this.bio = bio;
}
public int getCalories() {
return calories;
}
import lombok.Data;
import lombok.EqualsAndHashCode;
public void setCalories(int calories) {
this.calories = calories;
}
public boolean getBio() {
return bio;
}
@EqualsAndHashCode(callSuper = true)
@Data
public class Autre extends Ingredient {
public void setBio(boolean bio) {
this.bio = bio;
}
public Autre(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
Consigne[] consignes) {
super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
}
public String toString() {
return super.toString() + " Autre [calories=" + calories + ", bio=" + bio + "]";
}
}
package imt.ingredients;
public class Epice extends Ingredient{
private Boolean bio;
import lombok.Data;
import lombok.EqualsAndHashCode;
public Epice(int idIngredient, String nomIngredient, Boolean bio) {
super(idIngredient, nomIngredient);
this.bio = bio;
}
@EqualsAndHashCode(callSuper = true)
@Data
public class Epice extends Ingredient {
public Boolean getBio() {
return bio;
}
public Epice(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
Consigne[] consignes) {
super(idIngredient, nomIngredient, quantité, 0, bio, consignes);
}
public void setBio(Boolean bio) {
this.bio = bio;
}
public String toString() {
return super.toString() + " Epice [bio=" + bio + "]";
}
}
package imt.ingredients;
public class Ingredient {
private int idIngredient;
private String nomIngredient;
private int quantité;
private Consigne[] consignes;
public Ingredient(int idIngredient, String nomIngredient) {
this.idIngredient = idIngredient;
this.nomIngredient = nomIngredient;
this.quantité = 0;
this.consignes = null;
}
public int getIdIngredient() {
return idIngredient;
}
public void setIdIngredient(int idIngredient) {
this.idIngredient = idIngredient;
}
public String getNomIngredient() {
return nomIngredient;
}
public void setNomIngredient(String nomIngredient) {
this.nomIngredient = nomIngredient;
}
public int getQuantité() {
return quantité;
}
public void setQuantité(int quantité) {
this.quantité = quantité;
}
public Consigne[] getConsignes() {
return consignes;
}
public void setConsignes(Consigne[] consignes) {
this.consignes = consignes;
}
public String toString() {
String strConsigne = "";
for (int i = 0; i < consignes.length; i++) {
strConsigne += consignes[i].toString()+", ";
}
return "Ingredient [idIngredient=" + idIngredient + ", nomIngredient=" + nomIngredient + ", Consignes=" + strConsigne + "]";
}
import lombok.Data;
@Data
public abstract class Ingredient {
private final int idIngredient;
private final String nomIngredient;
private final int quantité;
private final int calories;
private final boolean bio;
private final Consigne[] consignes;
}
package imt.ingredients;
public class Legume extends Ingredient{
private int calories;
private boolean bio;
import lombok.Data;
import lombok.EqualsAndHashCode;
public Legume(int idIngredient, String nomIngredient, int calories, boolean bio) {
super(idIngredient, nomIngredient);
this.calories = calories;
this.bio = bio;
}
@EqualsAndHashCode(callSuper = true)
@Data
public class Legume extends Ingredient {
private final int fibres;
public int getCalories() {
return calories;
}
public Legume(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
Consigne[] consignes, int fibres) {
super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
this.fibres = fibres;
}
public void setCalories(int calories) {
this.calories = calories;
}
public boolean getBio() {
return bio;
}
public void setBio(boolean bio) {
this.bio = bio;
}
public String toString() {
return super.toString() + " Legume [calories=" + calories + ", bio=" + bio + "]";
}
}
package imt.ingredients;
public class ViandePoisson extends Ingredient{
private int calories;
private int gras;
public ViandePoisson(int idIngredient, String nomIngredient, int calories, int gras) {
super(idIngredient, nomIngredient);
this.calories = calories;
this.gras = gras;
}
public int getCalories() {
return calories;
}
public void setCalories(int calories) {
this.calories = calories;
}
public int getGras() {
return gras;
}
public void setGras(int gras) {
this.gras = gras;
}
public String toString() {
return super.toString() + " Viande/Poisson [calories=" + calories + ", gras=" + gras + "]";
}
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class ViandePoisson extends Ingredient {
private final int gras;
public ViandePoisson(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
Consigne[] consignes, int gras) {
super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
this.gras = gras;
}
}
\ No newline at end of file
package imt.ingredients;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
public class IngredientTest {
public static final Ingredient STEAK = new ViandePoisson(1, "steak", 1, 10, true, null, 0);
public static final Ingredient OIGNON = new Legume(2, "oignon", 1, 20, true, null, 0);
public static final Ingredient AUTRE = new Autre(3, "autre", 1, 30, false, null);
@Test
void epice_apportent_zero_calories() {
Ingredient epice = new Epice(1, "poivre", 1, 10, false, null);
assertThat(epice.getCalories()).isEqualTo(0);
}
@Test
void le_reste_apporte_des_calories() {
assertThat(STEAK.getCalories()).isEqualTo(10);
assertThat(OIGNON.getCalories()).isEqualTo(20);
assertThat(AUTRE.getCalories()).isEqualTo(30);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment