Skip to content
Snippets Groups Projects
Commit 5b02edef authored by Alexandre's avatar Alexandre
Browse files

tpOO-08::exo-miseEnRayon

parent 2a263656
No related branches found
No related tags found
No related merge requests found
package tpOO.tp08;
import java.time.LocalDate;
public class Food {
String label;
double price;
LocalDate bestBeforeDate;
Food(String label, double price, LocalDate bestBeforeDate){
this.label = label;
this.bestBeforeDate = bestBeforeDate;
this.price = price;
}
Food(String label, double price){
this(label, price, LocalDate.now().plusDays(10));
}
String getLabel(){
return this.label;
}
double getPrice(){
return this.price;
}
LocalDate getBestBeforeDate(){
return this.bestBeforeDate;
}
boolean isPerishable(){
return true;
}
@Override
public String toString(){
return this.label + "=>" + this.price + " à consommer avant le " + this.bestBeforeDate;
}
boolean isBestBefore(LocalDate date){
if(date.compareTo(this.bestBeforeDate)>0){
return false;
}
return true;
}
}
package tpOO.tp08;
public class Furniture {
}
package tpOO.tp08;
interface Iproduct{
double getPrice();
boolean isPerishable();
}
\ No newline at end of file
package tpOO.tp08;
public class Shelf {
}
package tpOO.tp08;
public class Shop {
}
package tpOO.tp08;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
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));
ArrayList<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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment