import java.util.ArrayList;
class food {
private ArrayList<food> foods = new ArrayList<>(3);
private int quantity;
private double cost;
private String foodtype;
public food(String foodtype, int qty, double cost) {
this.quantity = qty;
this.cost = cost;
this.foodtype = foodtype;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
this.cost = cost;
}
public void display() {
System.out.println("Food: " + this.foodtype);
System.out.println("Inventory: " + this.quantity);
System.out.println("Cost: $" + this.cost);
System.out.println("");
}
public void purchase(double amount) {
if (this.cost < amount) {
double changeToReturn = amount % this.cost;
System.out.println("Change to return: " + changeToReturn);
this.quantity -= (int) amount / this.cost;
}
}
public void inventory() {
this.quantity++;
}
}
public class Main
{
public static void main(String[] args) {
food apple = new food("Apple", 20, 70.0);
food grapes = new food("Grapes", 15, 40.0);
food bread = new food("Bread", 20, 30.0);
food noodles = new food("Noodles", 30, 50.0);
apple.inventory();
grapes.inventory();
bread.inventory();
noodles.inventory();
apple.purchase(100.0);
apple.display();
grapes.display();
bread.display();
noodles.display();
}
}