❓ Help Help me to fix it Javivo

V_1 M

Forum Guru

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
  • 265
    Views
  • 1
    Participants
Last reply from:
V_1 M

Trending Topics

Online now

Members online
1,153
Guests online
875
Total visitors
2,028

Forum statistics

Threads
2,273,754
Posts
28,951,323
Members
1,234,944
Latest member
zackcolins1129
Back
Top