Skip to content
Snippets Groups Projects
Commit 6f1da651 authored by Baptiste Royer's avatar Baptiste Royer
Browse files

Update 29 files

- /src/td07/Animaux.java
- /src/td07/Banc.java
- /src/td07/Fish.java
- /src/td07/Pig.java
- /src/td07/Tigre.java
- /tp08/.vscode/settings.json
- /tp08/lib/hamcrest-core-1.3.jar
- /tp08/lib/junit-4.13.2.jar
- /tp08/lib/junit-platform-console-standalone-1.10.2.jar
- /tp08/res/BreedingGroundTest.java
- /tp08/bin/tp08/Food.class
- /tp08/bin/tp08/Furniture.class
- /tp08/bin/tp08/IProduct.class
- /tp08/bin/tp08/Shelf.class
- /tp08/bin/tp08/Shop.class
- /tp08/bin/tp08/ShopTest.class
- /tp08/bin/tp08/UseComparable.class
- /tp08/src/tp08/Food.java
- /tp08/src/tp08/Furniture.java
- /tp08/src/tp08/IProduct.java
- /tp08/src/tp08/Shelf.java
- /tp08/src/tp08/Shop.java
- /tp08/src/tp08/ShopTest.java
- /tp08/src/tp08/UseComparable.java
- /tp09/src/td07/Animaux.java
- /tp09/src/td07/Banc.java
- /tp09/src/td07/Fish.java
- /tp09/src/td07/Pig.java
- /tp09/src/td07/Tigre.java
parent 4641b4d7
No related branches found
No related tags found
No related merge requests found
package tp08;
import java.util.ArrayList;
public class Shelf{
private boolean refregirated;
private int capacityMax;
private ArrayList<IProduct> products;
public Shelf(boolean refregirated, int capacityMax){
this.refregirated = refregirated;
this.capacityMax = capacityMax;
this.products = new ArrayList<IProduct>();
}
public ArrayList<IProduct> getShelves(){
return this.products;
}
public int getCapacityMax(){
return this.capacityMax;
}
public boolean isFull(){
return this.products.size() == this.capacityMax;
}
public boolean isEmpty(){
return this.products.size() == 0;
}
public boolean isRefregirated(){
return this.refregirated;
}
public String toString() {
return "[" + isRefregirated() + ": " + getCapacityMax() + " -> " + getShelves().toString() + "]";
}
public boolean add(IProduct product){
if(isFull()){
return false;
}
this.products.add(product);
return true;
}
}
\ No newline at end of file
package tp08;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
public class Shop {
private ArrayList<Shelf> shelves;
public Shop(){
this.shelves = new ArrayList<Shelf>();
}
public Shop(ArrayList<Shelf> shelves){
this.shelves = shelves;
}
public ArrayList<Shelf> getShelving(){
return this.shelves;
}
public String toString() {
String retour = "";
for(Shelf shelf : this.shelves){
retour += shelf.toString() + "\n";
}
return retour;
}
public void tidy(ArrayList<IProduct> products){
for(int i = 0; i<products.size(); i++) {
if(products.get(i).isPerishable()){
for(Shelf shelf : this.shelves){
if(shelf.isRefregirated() && shelf.add(products.get(i))){
products.remove(i);
i--;
break;
}
}
} else {
for(Shelf shelf : this.shelves){
if(!shelf.isRefregirated() && shelf.add(products.get(i))){
products.remove(i);
i--;
break;
}
}
}
}
}
public ArrayList<IProduct> closeBestBeforeDate(int nbDays) {
ArrayList<IProduct> retour = new ArrayList<IProduct>();
for (Shelf shelf : this.shelves) {
if(shelf.isRefregirated()) {
for (IProduct product : shelf.getShelves()) {
if (((Food)product).isBestBefore(LocalDate.now().plus(nbDays, ChronoUnit.DAYS))) {
retour.add(product);
}
}
}
}
return retour;
}
}
\ No newline at end of file
package tp08;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.time.LocalDate;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class ShopTest {
public IProduct p1, p2, p3, p4, p5;
public ArrayList<IProduct> aStock;
public Shelf e1, e2, e3, e4;
public ArrayList<Shelf> shelves;
public Shop m;
@BeforeEach
public void initialization() {
this.p1 = new Food("pasta", 3.25, LocalDate.of(2019, 1, 1));
this.p2 = new Furniture("chair", 50.0);
this.p3 = new Furniture("table", 100.0);
this.p4 = new Food("fish", 10.0);
this.p5 = new Food("meat", 15.0, LocalDate.of(2019, 1, 1));
this.aStock = new ArrayList<IProduct>();
this.aStock.add(p1); this.aStock.add(p2); this.aStock.add(p3); this.aStock.add(p4); this.aStock.add(p5);
this.e1 = new Shelf(false, 1);
this.e2 = new Shelf(false, 2);
this.e3 = new Shelf(true, 2);
this.e4 = new Shelf(true, 2);
this.shelves = new ArrayList<Shelf>();
this.shelves.add(e1); this.shelves.add(e2); this.shelves.add(e3); this.shelves.add(e4);
this.m = new Shop(shelves);
}
@Test
public void initTest() {
ArrayList<Shelf> tmp = m.getShelving();
assertEquals(4, tmp.size());
assertTrue(tmp.get(0).isEmpty());
assertFalse(tmp.get(0).isRefregirated());
assertTrue(tmp.get(1).isEmpty());
assertFalse(tmp.get(1).isRefregirated());
assertTrue(tmp.get(2).isEmpty());
assertTrue(tmp.get(2).isRefregirated());
assertTrue(tmp.get(3).isEmpty());
assertTrue(tmp.get(3).isRefregirated());
}
@Test
public void tidyTest() {
ArrayList<Shelf> tmp = m.getShelving();
m.tidy(this.aStock);
assertTrue(tmp.get(0).isFull());
assertEquals(this.p2, tmp.get(0).getShelves().get(0));
assertFalse(tmp.get(1).isFull());
assertFalse(tmp.get(1).isEmpty());
assertEquals(this.p3, tmp.get(1).getShelves().get(0));
assertTrue(tmp.get(2).isFull());
assertEquals(this.p1, tmp.get(2).getShelves().get(0));
assertEquals(this.p4, tmp.get(2).getShelves().get(1));
assertFalse(tmp.get(3).isFull());
assertFalse(tmp.get(3).isEmpty());
assertEquals(this.p5, tmp.get(3).getShelves().get(0));
}
@Test
public void closeBeforeDateTest() {
m.tidy(this.aStock);
ArrayList<IProduct> res = m.closeBestBeforeDate(-3);
assertEquals(2, res.size());
assertEquals(this.p1, res.get(0));
assertEquals(this.p5, res.get(1));
}
}
package tp08;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class UseComparable{
public static void main(String[] args) {
Food f1 = new Food("pasta", 3.25, LocalDate.of(2019, 1, 1));
Food f2 = new Food("fish", 10.0, LocalDate.of(2019, 1, 10));
Food f3 = new Food("meat", 15.0, LocalDate.of(2019, 1, 3));
List<Food> storage = new ArrayList<Food>();
storage.add(f1);storage.add(f2);storage.add(f3);
System.out.println(storage);
Collections.sort(storage);
System.out.println(storage);
}
}
\ No newline at end of file
package td07;
public interface Animaux {
public String shout();
public int foodAmount();
public boolean isPet();
}
\ No newline at end of file
package td07;
public class Banc {
}
\ No newline at end of file
package td07;
public class Fish implements Animaux{
private static final int FOOD = 1; //En UML, un final doit être écrit en majuscules.
private String name;
public Fish(String name) { //+Fish(String)
this.name = name;
}
public String shout() { //+shout() : String
return "Blob!";
}
public int foodAmount() {
return this.FOOD; //+foodAmount() : int
}
public boolean isPet() { //+isPet() : boolean
return true;
}
public String toString() { //+toString() : String
return "";
}
public int getFOOD() { //+getFOOD() : int
return this.mealSize;
}
public int getName() { //+getName() : String
return this.weight;
}
}
\ No newline at end of file
package td07;
public class Pig implements Animaux{
private static int mealSize; //En UML, static doit être souligné.
private int weight;
private String name;
public Pig(String name, int weight) { //+Pig(String, int)
this.name = name;
this.weight = weight;
}
public String shout() { //shout() : String
return "Grouik!";
}
public int foodAmount() { //foodAmount() : int
return this.mealSize;
}
public boolean isPet() { //isPet() : boolean
return true;
}
public void rollingInMud() { //rollingInMud() : void
println("Rolls in the mud.");
}
public String toString() { //toString() : String
return "";
}
public int getMealSize() { //getMealSize() : int
return this.mealSize;
}
public int getWeight() { //getWeight() : int
return this.weight;
}
public String getName() { //getName() : String
return this.name;
}
}
\ No newline at end of file
package td07;
public class Tigre implements Animaux{
private static final int MIN_FOOD = 0; //En UML, un final doit être écrit en majuscules.
private static final int MAX_FOOD = 20;
public Tiger() { //+Tigre()
}
public String shout() { //+shout() : String
return "Purr!";
}
public int foodAmount() { //+foodAmount() : int
}
public boolean isPet() { //+isPet() : boolean
return true;
}
public String toString() { //+toString() : String
return "";
}
public int getMIN_FOOD() { //+getMIN_FOOD() : int
return this.mealSize;
}
public int getWeight() { //+getMAX_FOOD() : int
return this.weight;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment