From f15c086b0a7cb88465b7c7a6ff01359de176c196 Mon Sep 17 00:00:00 2001
From: Samuel Turpin <samuel.turpin.etu@univ-lille.fr>
Date: Wed, 15 May 2024 22:34:25 +0200
Subject: [PATCH] tp8

---
 .../devinelenombre/DevineNombre.java          | 45 +++++-----
 src/td08/Mat.java                             |  6 ++
 src/td08/Person.java                          | 20 +++++
 src/td08/Student.java                         | 86 +++++++++++++++++++
 src/tp08/Food.java                            | 55 ++++++++++++
 src/tp08/Furniture.java                       | 41 +++++++++
 src/tp08/IProduct.java                        |  7 ++
 src/tp08/Shelf.java                           | 71 +++++++++++++++
 src/tp08/Shop.java                            | 31 +++++++
 src/tp08/UseComparable.java                   | 21 +++++
 10 files changed, 361 insertions(+), 22 deletions(-)
 create mode 100644 src/td08/Mat.java
 create mode 100644 src/td08/Person.java
 create mode 100644 src/td08/Student.java
 create mode 100644 src/tp08/Food.java
 create mode 100644 src/tp08/Furniture.java
 create mode 100644 src/tp08/IProduct.java
 create mode 100644 src/tp08/Shelf.java
 create mode 100644 src/tp08/Shop.java
 create mode 100644 src/tp08/UseComparable.java

diff --git a/src/projetjeu/devinelenombre/DevineNombre.java b/src/projetjeu/devinelenombre/DevineNombre.java
index 2b02fb5..4145bf1 100644
--- a/src/projetjeu/devinelenombre/DevineNombre.java
+++ b/src/projetjeu/devinelenombre/DevineNombre.java
@@ -17,32 +17,33 @@ public class DevineNombre
         m("Et toi tu devras le retrouver...");
         m("Tu dispose de 5 tentatives...");
         Random rnd = new Random();
-        Scanner sc = new Scanner(System.in);
-        int nb = rnd.nextInt(1,100);
-        int lives = 5;
-        int reponse = 0;
-        while(lives != 0)
-        {
-            m("Nombre de Vies : " + lives);
-            reponse = sc.nextInt();
-            if(reponse == nb)
+        try (Scanner sc = new Scanner(System.in)) {
+            int nb = rnd.nextInt(1,100);
+            int lives = 5;
+            int reponse = 0;
+            while(lives != 0)
             {
-                m("Bravo tu as réussis le nombre était " + nb);
-                lives=0;
+                m("Nombre de Vies : " + lives);
+                reponse = sc.nextInt();
+                if(reponse == nb)
+                {
+                    m("Bravo tu as réussis le nombre était " + nb);
+                    lives=0;
+                }
+                else if (reponse < nb)
+                {
+                    m("C'est plus !");
+                }
+                else if (reponse > nb)
+                {
+                    m("C'est moins !");
+                }
+                lives=lives-1;
             }
-            else if (reponse < nb)
+            if(reponse != nb)
             {
-                m("C'est plus !");
+                m("Perdu, le nombre était " + nb);
             }
-            else if (reponse > nb)
-            {
-                m("C'est moins !");
-            }
-            lives=lives-1;
-        }
-        if(reponse != nb)
-        {
-            m("Perdu, le nombre était " + nb);
         }
     }
 }
\ No newline at end of file
diff --git a/src/td08/Mat.java b/src/td08/Mat.java
new file mode 100644
index 0000000..211a290
--- /dev/null
+++ b/src/td08/Mat.java
@@ -0,0 +1,6 @@
+package td08;
+
+public enum Mat
+{
+    ALGO, BDD, SYS, COM, EN, PPP, MATH, GESTION;
+}
\ No newline at end of file
diff --git a/src/td08/Person.java b/src/td08/Person.java
new file mode 100644
index 0000000..e9fd8c9
--- /dev/null
+++ b/src/td08/Person.java
@@ -0,0 +1,20 @@
+package td08;
+
+import java.time.LocalDate;
+
+public class Person
+{
+    private String nom;
+    private LocalDate Birth;
+   
+    public Person(String n, LocalDate d)
+    {
+        this.nom=n;
+        this.Birth=d;
+    }
+
+    public long getAges()
+    {
+        return Birth.toEpochDay();
+    }
+}
\ No newline at end of file
diff --git a/src/td08/Student.java b/src/td08/Student.java
new file mode 100644
index 0000000..3699fc5
--- /dev/null
+++ b/src/td08/Student.java
@@ -0,0 +1,86 @@
+package td08;
+
+import java.time.LocalDate;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Student
+{
+    private final String INE;
+    private String nom;
+    private LocalDate Birth;
+    private Map<Mat, Double> grades;
+    private Person person;
+    private boolean pedago = false;
+
+    public Student(String n, LocalDate anniv, Map<Mat, Double> g)
+    {
+        this.nom=n;
+        this.Birth=anniv;
+        this.grades=g;
+        this.person=new Person(n, anniv);
+        this.INE="0";
+        this.pedago=true;
+    }
+
+    public Student(String n, LocalDate d)
+    {
+        this(n, d, new HashMap<>());
+        this.pedago=false;
+    }
+
+    public long getAges()
+    {
+        return this.person.getAges();
+    }
+
+    public String getNom() {
+        return nom;
+    }
+
+    public LocalDate getBirth() {
+        return Birth;
+    }
+
+    public void addGrade(Mat mat, double grade)
+    {
+        this.grades.put(mat, grade);
+    }
+
+    public void addGrade(String mat, double grade)
+    {
+        this.addGrade(Mat.valueOf(mat.toUpperCase()), grade);
+    }
+
+    public double computeOverall()
+    {
+        double calcul=0.0;
+        if(grades.size()==0)
+        {
+            return -1;
+        }
+        else
+        {
+            for(Double d : grades.values())
+            {
+                calcul=calcul+d;
+            }
+            double fCalc = calcul/grades.size();
+            return fCalc;
+        }
+    }
+
+    @Override
+    public String toString()
+    {
+        if(this.pedago)
+        {
+            
+        }
+        else
+        {
+
+        }
+        return super.toString();
+    }
+}
\ No newline at end of file
diff --git a/src/tp08/Food.java b/src/tp08/Food.java
new file mode 100644
index 0000000..a5fbb7e
--- /dev/null
+++ b/src/tp08/Food.java
@@ -0,0 +1,55 @@
+package tp08;
+
+import java.time.LocalDate;
+
+public class Food implements IProduct, Comparable<Food>
+{
+    private String label = "refUnknownXXX";
+    private double price;
+    private LocalDate beforeRots;
+
+    public Food(String l, double p, LocalDate rots)
+    {
+        this.label=l;
+        this.price=p;
+        this.beforeRots=rots;
+    }
+
+    public Food(String l, double p)
+    {
+        this(l, p, LocalDate.now().minusDays(10));
+    }
+
+    @Override
+    public double getPrice()
+    {
+        return this.price;
+    }
+
+    @Override
+    public int compareTo(Food o)
+    {
+        return this.beforeRots.compareTo(o.beforeRots);
+    }
+
+    public boolean isNotRotten(LocalDate aDate)
+    {
+        if(this.beforeRots==aDate)
+        {
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public boolean isPerishable()
+    {
+        return true;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "["+this.label+"="+getPrice()+" -> " + this.beforeRots+"]";
+    }
+}
\ No newline at end of file
diff --git a/src/tp08/Furniture.java b/src/tp08/Furniture.java
new file mode 100644
index 0000000..eb0858a
--- /dev/null
+++ b/src/tp08/Furniture.java
@@ -0,0 +1,41 @@
+package tp08;
+
+public class Furniture implements IProduct, Comparable<Furniture>
+{
+    private String label = "refUnknownXXX";
+    private double price;
+
+    public Furniture(String l, double p)
+    {
+        this.label=l;
+        this.price=p;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    @Override
+    public double getPrice()
+    {
+        return this.price;
+    }
+
+    @Override
+    public int compareTo(Furniture o)
+    {
+        return this.label.compareTo(o.label);
+    }
+
+    @Override
+    public boolean isPerishable()
+    {
+        return false;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "["+this.label+"="+getPrice()+" -> Never Perishable]";
+    }
+}
\ No newline at end of file
diff --git a/src/tp08/IProduct.java b/src/tp08/IProduct.java
new file mode 100644
index 0000000..f3a86a9
--- /dev/null
+++ b/src/tp08/IProduct.java
@@ -0,0 +1,7 @@
+package tp08;
+
+public interface IProduct
+{
+    double getPrice();
+    boolean isPerishable();
+}
\ No newline at end of file
diff --git a/src/tp08/Shelf.java b/src/tp08/Shelf.java
new file mode 100644
index 0000000..f21131e
--- /dev/null
+++ b/src/tp08/Shelf.java
@@ -0,0 +1,71 @@
+package tp08;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Shelf
+{
+    private boolean refridge;
+    private int capacityMax;
+    private List<IProduct> shelves;
+
+    public Shelf(boolean r, int c)
+    {
+        this.refridge=r;
+        this.capacityMax=c;
+        this.shelves = new ArrayList<>();
+    }
+
+    public List<IProduct> getShelves()
+    {
+        return this.shelves;
+    }
+
+    public boolean add(IProduct item)
+    {
+        if(isFull())
+        {
+            return false;
+        }
+        else
+        {
+            getShelves().add(item);
+            return true;
+        }
+    }
+
+    public boolean isFull()
+    {
+        if(!isEmpty() && this.capacityMax == this.shelves.size())
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public boolean isEmpty()
+    {
+        if(this.shelves.isEmpty())
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public boolean isRefrigerated()
+    {
+        return this.refridge;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "["+this.refridge+" : "+this.capacityMax+" -> "+this.shelves.toString()+"]";
+    }
+}
diff --git a/src/tp08/Shop.java b/src/tp08/Shop.java
new file mode 100644
index 0000000..7ed04a0
--- /dev/null
+++ b/src/tp08/Shop.java
@@ -0,0 +1,31 @@
+package tp08;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Shop
+{
+    private List<Shelf> shop;
+
+    public Shop() {}
+
+    public Shop(List<Shelf> s)
+    {
+        this.shop=s;
+    }
+
+    public List<Shelf> getShelving()
+    {
+        return this.shop;
+    }
+
+    public void tidy(ArrayList<IProduct> aStock)
+    {
+        
+    }
+
+    @Override
+    public String toString() {
+        return super.toString();
+    }
+}
\ No newline at end of file
diff --git a/src/tp08/UseComparable.java b/src/tp08/UseComparable.java
new file mode 100644
index 0000000..20528d3
--- /dev/null
+++ b/src/tp08/UseComparable.java
@@ -0,0 +1,21 @@
+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
-- 
GitLab