import java.util.ArrayList;
class food {
private ArrayList<food> foods = new ArrayList<>(3);
private int quantity;
private double cost;
public food(int qty, double cost) {
this.quantity = qty;
this.cost = cost;
}
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 displayInfo() {
for (food foodItem : foods) {
System.out.println("Food Item quantity in store: " + foodItem.getQuantity());
System.out.println("Food Item price: " + foodItem.getCost());
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(food foodToAdd) {
this.foods.add(foodToAdd);
}
}
public class Main
{
public static void main(String[] args) {
food apple = new food(20, 70.0);
food grapes = new food(15, 40.0);
food bread = new food(20, 30.0);
food noodles = new food(30, 50.0);
apple.inventory(apple);
grapes.inventory(grapes);
bread.inventory(bread);
noodles.inventory(noodles);
apple.purchase(100.0);
apple.displayInfo();
grapes.displayInfo();
bread.displayInfo();
noodles.displayInfo();
}
}