❓ Help Help me to fix it Javivo

V_1 M

Elite

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
// ...
}
 

About this Thread

  • 0
    Replies
  • 298
    Views
  • 1
    Participants
Last reply from:
V_1 M

Trending Topics

Online now

Members online
606
Guests online
1,153
Total visitors
1,759

Forum statistics

Threads
2,284,335
Posts
29,022,556
Members
1,220,904
Latest member
Terrier4423
Back
Top