diff --git a/tp06 b/tp06 new file mode 160000 index 0000000000000000000000000000000000000000..a3a413ddd7a02a4055d86a2a8452438bba4ab392 --- /dev/null +++ b/tp06 @@ -0,0 +1 @@ +Subproject commit a3a413ddd7a02a4055d86a2a8452438bba4ab392 diff --git a/tp08/.vscode/settings.json b/tp08/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..c995aa5cefc39b8d1744799a04f27ee68d687c6b --- /dev/null +++ b/tp08/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.debug.settings.onBuildFailureProceed": true +} \ No newline at end of file diff --git a/tp08/bin/tp08/Food.class b/tp08/bin/tp08/Food.class new file mode 100644 index 0000000000000000000000000000000000000000..995b780b01e65d58aba3a6f72cafa52f42899aa4 Binary files /dev/null and b/tp08/bin/tp08/Food.class differ diff --git a/tp08/bin/tp08/Furniture.class b/tp08/bin/tp08/Furniture.class new file mode 100644 index 0000000000000000000000000000000000000000..1c7e0f97be203844db63e501af39bfcb60839a63 Binary files /dev/null and b/tp08/bin/tp08/Furniture.class differ diff --git a/tp08/bin/tp08/IProduct.class b/tp08/bin/tp08/IProduct.class new file mode 100644 index 0000000000000000000000000000000000000000..a17d8ba345927f98e1c989e9b81fc652b45fcd42 Binary files /dev/null and b/tp08/bin/tp08/IProduct.class differ diff --git a/tp08/bin/tp08/Shelf.class b/tp08/bin/tp08/Shelf.class new file mode 100644 index 0000000000000000000000000000000000000000..e3d454b46e6b9b8705b48525d1c69d350a2bf3ad Binary files /dev/null and b/tp08/bin/tp08/Shelf.class differ diff --git a/tp08/bin/tp08/Shop.class b/tp08/bin/tp08/Shop.class new file mode 100644 index 0000000000000000000000000000000000000000..8f7b4d62db0512920a4f217e29c03ea892da5d36 Binary files /dev/null and b/tp08/bin/tp08/Shop.class differ diff --git a/tp08/bin/tp08/ShopTest.class b/tp08/bin/tp08/ShopTest.class new file mode 100644 index 0000000000000000000000000000000000000000..0998777c6bf61697ffc592f3cab4f25dc900dfc1 Binary files /dev/null and b/tp08/bin/tp08/ShopTest.class differ diff --git a/tp08/bin/tp08/UseComparable.class b/tp08/bin/tp08/UseComparable.class new file mode 100644 index 0000000000000000000000000000000000000000..d60712e3f6353cda5b6f1db400b9d0c9f4252e17 Binary files /dev/null and b/tp08/bin/tp08/UseComparable.class differ diff --git a/tp08/lib/hamcrest-core-1.3.jar b/tp08/lib/hamcrest-core-1.3.jar new file mode 100644 index 0000000000000000000000000000000000000000..9d5fe16e3dd37ebe79a36f61f5d0e1a69a653a8a Binary files /dev/null and b/tp08/lib/hamcrest-core-1.3.jar differ diff --git a/tp08/lib/junit-4.13.2.jar b/tp08/lib/junit-4.13.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..6da55d8b8520dcc03c250a605151cc0d23a45518 Binary files /dev/null and b/tp08/lib/junit-4.13.2.jar differ diff --git a/tp08/lib/junit-platform-console-standalone-1.10.2.jar b/tp08/lib/junit-platform-console-standalone-1.10.2.jar new file mode 100644 index 0000000000000000000000000000000000000000..7ca10e60183a168b228fd60a233281dd697b1cea Binary files /dev/null and b/tp08/lib/junit-platform-console-standalone-1.10.2.jar differ diff --git a/tp08/res/BreedingGroundTest.java b/tp08/res/BreedingGroundTest.java new file mode 100755 index 0000000000000000000000000000000000000000..7c4ab87d94fc2c71f8c8640481f2bc167995166b --- /dev/null +++ b/tp08/res/BreedingGroundTest.java @@ -0,0 +1,139 @@ +package tpOO.tp08; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BreedingGroundTest { + public Participant p1,p2,p3,p4,p5,p6,p7,p8,p9,p10; + public BreedingGround v1,v2,v3; + public List<Participant> partList; + public Set<Participant> partSet; + + @BeforeEach + public void initTest() { + partList = new ArrayList<Participant>(); + partSet = new HashSet<Participant>(); + + p1 = new Participant("alice"); + p2 = new Participant("bruno"); // the cheater registered in v1 and v3 + p3 = new Participant("clement"); + p4 = new Participant("dominique"); + p5 = new Participant("elia"); + p6 = new Participant("flore"); + p7 = new Participant("gudul"); + p8 = new Participant("hercule"); + p9 = new Participant("isidor"); + p10 = new Participant("jules"); + // appariement des participants + p1.matchWith(p2); + p5.matchWith(p6); + p8.matchWith(p9); + + v1 = new BreedingGround(); + v1.registration(p1); + v1.registration(p2); + v1.registration(p3); + v1.registration(p4); + v2 = new BreedingGround(); + v2.registration(p5); + v2.registration(p6); + v3 = new BreedingGround(); + v3.registration(p8); + v3.registration(p9); + v3.registration(p10); + v3.registration(p2); + } + + @Test + public void testRegistration() { + assertEquals(4, v1.getApplicants().size()); + assertTrue(v1.getApplicants().contains(p1) && v1.getApplicants().contains(p2) + && v1.getApplicants().contains(p3) && v1.getApplicants().contains(p4)); + v1.clear(); + assertEquals(Collections.emptySet(), v1.getApplicants()); + assertTrue(v1.registration(p1)); + assertEquals(1, v1.getApplicants().size()); + assertTrue(v1.getApplicants().contains(p1)); + assertFalse(v1.registration(p1)); + } + @Test + public void testLoners() { + assertEquals(0, v2.loners().size()); + assertEquals(Collections.emptyList(), v2.loners()); + partList = v1.loners(); + assertEquals(2, partList.size()); + assertTrue(partList.contains(p3) && partList.contains(p4)); + } + @Test + public void testLonersCleansing() { + v1.lonersCleansing(); + assertEquals(2, v1.getApplicants().size()); + assertTrue(v1.getApplicants().contains(p1) && v1.getApplicants().contains(p2)); + v2.lonersCleansing(); + assertEquals(2, v2.getApplicants().size()); + assertTrue(v2.getApplicants().contains(p5) && v2.getApplicants().contains(p6)); + } + @Test + public void testCheaters() { + assertEquals(Collections.emptyList(), v1.cheaters(v2)); + partList.add(p2); + assertEquals(partList, v1.cheaters(v3)); + } + @Test + public void testCheatersBan() { + assertTrue(p1.isMatchedWith(p2)); + assertTrue(p2.isMatchedWith(p1)); + v1.isolateCheater(p2); + assertFalse(p1.isMatchedWith(p2)); + assertFalse(p2.isMatchedWith(p1)); + } + @Test + public void testCheatersCleansing() { + partSet = v1.getApplicants(); + v1.cheatersCleansing(v2); + assertEquals(partSet, v1.getApplicants()); + partSet.clear(); + partSet.add(p1); partSet.add(p3); partSet.add(p4); + v1.cheatersCleansing(v3); + assertEquals(partSet, v1.getApplicants()); + } + @Test + public void testPossibleMerging() { + assertFalse(v1.possibleMerging(v1)); + assertTrue(v1.possibleMerging(v2)); + assertFalse(v1.possibleMerging(v3)); + } + @Test + public void testMerge() { + partSet = v1.getApplicants(); + partSet.addAll(v2.getApplicants()); + v1.merging(v2); + assertEquals(partSet, v1.getApplicants()); + partSet.clear(); + partSet.addAll(v1.getApplicants()); + partSet.addAll(v2.getApplicants()); + partSet.addAll(v3.getApplicants()); + v1.merging(v3); + assertEquals(partSet, v1.getApplicants()); + } + @Test + public void testSecuredMerging() { + partSet = v1.getApplicants(); + partSet.add(p8); partSet.add(p9); partSet.add(p10); + v1.securedMerging(v3); + assertEquals(partSet, v1.getApplicants()); + partSet.addAll(v2.getApplicants()); + v1.securedMerging(v2); + assertEquals(partSet, v1.getApplicants()); + } +} diff --git a/tp08/src/tp08/Food.java b/tp08/src/tp08/Food.java new file mode 100644 index 0000000000000000000000000000000000000000..2dff960fb0728b559a858642218db0a3d27bbefb --- /dev/null +++ b/tp08/src/tp08/Food.java @@ -0,0 +1,65 @@ +package tp08; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; + +public class Food implements IProduct, Comparable<Food> { + private String label; + private double price; + private LocalDate bestBeforDate; + private static int refIconnue = 0; + + public Food(String label, double price, LocalDate bestBeforDate) { + if(label == null) { + this.label = "refUnknown" + refIconnue; + refIconnue++; + } else { + this.label = label; + } + this.price = price; + this.bestBeforDate = bestBeforDate; + } + + public Food(String label, double price) { + if(label == null) { + this.label = "refUnknown" + refIconnue; + refIconnue++; + } else { + this.label = label; + } + this.price = price; + this.bestBeforDate = LocalDate.now().plus(10, ChronoUnit.DAYS); + } + + public String getLabel() { + return this.label; + } + + public double getPrice() { + return this.price; + } + + public LocalDate getBestBeforDate() { + return this.bestBeforDate; + } + + public boolean isPerishable() { + return true; + } + + public boolean isBestBefore(LocalDate date) { + return this.bestBeforDate.isBefore(date); + } + + @Override + public int compareTo(Food arg0) { + if(this.isBestBefore(arg0.getBestBeforDate())) { + return 1; + } else { + return -1; + } + } + + public String toString() { + return "[" + this.label + "=" + this.price + " -> before " + this.bestBeforDate + "]"; + } +} \ No newline at end of file diff --git a/tp08/src/tp08/Furniture.java b/tp08/src/tp08/Furniture.java new file mode 100644 index 0000000000000000000000000000000000000000..cd3756f892eff4a708987611594619ed6a90b07d --- /dev/null +++ b/tp08/src/tp08/Furniture.java @@ -0,0 +1,32 @@ +package tp08; +public class Furniture implements IProduct { + private String label; + private double price; + private static int refInconnue = 0; + + public Furniture(String label, double price) { + if(label == null) { + this.label = "refUnknown" + refInconnue; + refInconnue++; + } else { + this.label = label; + } + this.price = price; + } + + public String getLabel() { + return this.label; + } + + public double getPrice() { + return this.price; + } + + public boolean isPerishable() { + return false; + } + + public String toString() { + return "[" + this.label + "=" + this.price + "]"; + } +} \ No newline at end of file diff --git a/tp08/src/tp08/IProduct.java b/tp08/src/tp08/IProduct.java new file mode 100644 index 0000000000000000000000000000000000000000..3402ad9d1acf64c436934a30a4fbeeac5ba2f69e --- /dev/null +++ b/tp08/src/tp08/IProduct.java @@ -0,0 +1,6 @@ +package tp08; +public interface IProduct { + + public double getPrice(); + public boolean isPerishable(); +} \ No newline at end of file diff --git a/tp08/src/tp08/Shelf.java b/tp08/src/tp08/Shelf.java new file mode 100644 index 0000000000000000000000000000000000000000..d233f617c88b5d8f93325f085f904d6b2eebe6a8 --- /dev/null +++ b/tp08/src/tp08/Shelf.java @@ -0,0 +1,47 @@ +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 diff --git a/tp08/src/tp08/Shop.java b/tp08/src/tp08/Shop.java new file mode 100644 index 0000000000000000000000000000000000000000..8e19d42ecb8e5aa3f3016e1ff58e67362a6a0143 --- /dev/null +++ b/tp08/src/tp08/Shop.java @@ -0,0 +1,64 @@ +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 diff --git a/tp08/src/tp08/ShopTest.java b/tp08/src/tp08/ShopTest.java new file mode 100644 index 0000000000000000000000000000000000000000..169b27e0ca202df1df2bce8e8f905046c98246eb --- /dev/null +++ b/tp08/src/tp08/ShopTest.java @@ -0,0 +1,76 @@ +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)); + } +} diff --git a/tp08/src/tp08/UseComparable.java b/tp08/src/tp08/UseComparable.java new file mode 100644 index 0000000000000000000000000000000000000000..5442921a4f6c476e5ae8e8a270482a2803ca811c --- /dev/null +++ b/tp08/src/tp08/UseComparable.java @@ -0,0 +1,18 @@ +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 diff --git a/tp09/src/td07/Animaux.java b/tp09/src/td07/Animaux.java new file mode 100644 index 0000000000000000000000000000000000000000..f3d98f0563021fffb4c4facb199df27a51dc452d --- /dev/null +++ b/tp09/src/td07/Animaux.java @@ -0,0 +1,7 @@ +package td07; + +public interface Animaux { + public String shout(); + public int foodAmount(); + public boolean isPet(); +} \ No newline at end of file diff --git a/tp09/src/td07/Banc.java b/tp09/src/td07/Banc.java new file mode 100644 index 0000000000000000000000000000000000000000..ad8c5d79ad430443643e8dcb5322f2c999a8bd72 --- /dev/null +++ b/tp09/src/td07/Banc.java @@ -0,0 +1,5 @@ +package td07; + +public class Banc { + +} \ No newline at end of file diff --git a/tp09/src/td07/Fish.java b/tp09/src/td07/Fish.java new file mode 100644 index 0000000000000000000000000000000000000000..485836963780201668c308d8cb0b184a4b278283 --- /dev/null +++ b/tp09/src/td07/Fish.java @@ -0,0 +1,34 @@ +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 diff --git a/tp09/src/td07/Pig.java b/tp09/src/td07/Pig.java new file mode 100644 index 0000000000000000000000000000000000000000..e351f7dc2b36f4ca56af356955233fa5631ebf2e --- /dev/null +++ b/tp09/src/td07/Pig.java @@ -0,0 +1,44 @@ +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 diff --git a/tp09/src/td07/Tigre.java b/tp09/src/td07/Tigre.java new file mode 100644 index 0000000000000000000000000000000000000000..bda0be11b06162540f1ab09b1d5a905f74602a4d --- /dev/null +++ b/tp09/src/td07/Tigre.java @@ -0,0 +1,32 @@ +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