Skip to content
Snippets Groups Projects
Commit f15c086b authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

tp8

parent eefa2917
Branches
No related tags found
No related merge requests found
......@@ -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
package td08;
public enum Mat
{
ALGO, BDD, SYS, COM, EN, PPP, MATH, GESTION;
}
\ No newline at end of file
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
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
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
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
package tp08;
public interface IProduct
{
double getPrice();
boolean isPerishable();
}
\ No newline at end of file
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()+"]";
}
}
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment