diff --git a/src/projetjeu/devinelenombre/DevineNombre.java b/src/projetjeu/devinelenombre/DevineNombre.java index 2b02fb5bd63747655bb6188dfbfd9d8f38d0eedc..4145bf15b336b083745fda5da37eec93fe09616d 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 0000000000000000000000000000000000000000..211a2907563c2b205662a8bf5f20b5893075e9bf --- /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 0000000000000000000000000000000000000000..e9fd8c9057d0c568861859aff495c2f5b060ebc5 --- /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 0000000000000000000000000000000000000000..3699fc5ebca325614c67aa842744515a33f0b7c6 --- /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 0000000000000000000000000000000000000000..a5fbb7e2b71d2dc92d9df2e24fbdb86d3f048e22 --- /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 0000000000000000000000000000000000000000..eb0858afd94faec72f8c42b04a8ea41c256b1223 --- /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 0000000000000000000000000000000000000000..f3a86a965f9107806412a51f165e7a5a79fcf61b --- /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 0000000000000000000000000000000000000000..f21131e26bd3a2ba033a3ecd64471458ff817b30 --- /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 0000000000000000000000000000000000000000..7ed04a0aeba158821aecfda9eca37a3bed0b1864 --- /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 0000000000000000000000000000000000000000..20528d3874cb8d52bdbd356fa2cae1e2ab3d29d7 --- /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