Skip to content
Snippets Groups Projects
Commit 3330947a authored by Malori Alvarez's avatar Malori Alvarez
Browse files

TP5 - TP 7

parent 6f5c77ae
No related branches found
No related tags found
No related merge requests found
Showing
with 58 additions and 0 deletions
No preview for this file type
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
No preview for this file type
package tp8;
import java.time.LocalDate;
public class Food implements IProduct, Comparable<Food> {
// Attributs
private String label;
private double price;
private LocalDate isBestBefore;
private static int XXX = 0;
// Constructeurs
public Food(String label, double price, LocalDate isBestBefore) {
this.label = label;
this.price = price;
this.isBestBefore = isBestBefore;
}
public Food(String label, double price) {
this(label, price, LocalDate.now().plusDays(10));
}
public Food(double price, LocalDate isBestBefore) {
this.label = "refUnknown" + Food.XXX;
Food.XXX++;
this.price = price;
this.isBestBefore = isBestBefore;
}
// Méthodes
public boolean isPerishable() {
return true;
}
@Override
public String toString() {
return "[" + this.label + "=" + this.price + " -> before" + this.isBestBefore + "]";
}
boolean isBestBefore() {
return LocalDate.now().isAfter(this.isBestBefore);
}
@Override
public int compareTo(Food other) {
return this.isBestBefore.compareTo(other.isBestBefore);
}
}
package tp8;
public interface IProduct {
public double getPrice();
public boolean isPerishable();
}
\ 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