1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class Item {
public static void main(String[] args) {
Item i1 = new Item("Vodka", "Une bouteille de Vodka", 5483918746738L, 75.5);
Item i2 = new Item("Filet de citron 200g", 5473664615361L, 3.25);
System.err.println(""+i1);
System.err.println(""+i2);
}
private String name, description;
private long barcode;
private double price;
public Item(String name, String description, long barcode, double price) {
this.name = name;
this.description = description;
this.barcode = barcode;
this.price = price;
}
public Item(String name, long barcode, double price) {
this(name, "", barcode, price);
}
public double getPrice() {
return price;
}
public double getPrice(int q) {
double tot = price * q;
if (q >= 10) {
tot = tot * 0.95;
}
return tot;
}
@Override
public String toString() {
return "Item [name=" + name + ", description=" + description + ", barcode=" + barcode + ", price=" + price + "]";
}
} |
Partager