Fix my codes: fulfill the getter setter and other method needed
Main.java
public class Main {
public static void main(String[] args) {
// Handle user input and interaction here
}
}
Item.java
public class Item {
private String name;
private int quantity;
// Constructor
public Item(String name, int quantity) {
this.name = name;
this.quantity = quantity;
}
// Getters and setters
// ...
// Other methods
// ...
}
FoodItem.java
public class FoodItem extends Item {
private String expirationDate;
// Constructor
public FoodItem(String name, int quantity, String expirationDate) {
super(name, quantity);
this.expirationDate = expirationDate;
}
// Getters and setters
// ...
// Other methods
// ...
}
NonFoodItem.java
public class NonFoodItem extends Item {
private String usage;
// Constructor
public NonFoodItem(String name, int quantity, String usage) {
super(name, quantity);
this.usage = usage;
}
// Getters and setters
// ...
// Other methods
// ...
}
Pantry.java
import java.util.ArrayList;
import java.util.List;
public class Pantry {
private List<Item> items;
// Constructor
public Pantry() {
this.items = new ArrayList<>();
}
// Getters and setters
// ...
// Other methods
public void addItem(Item item) {
items.add(item);
}
public void removeItem(Item item) {
items.remove(item);
}
public Item getItemByName(String name) {
for (Item item : items) {
if (item.getName().equals(name)) {
return item;
}
}
return null;
}
// Other CRUD operations
// ...
}