I have a delivery project which consists the class names below:
FoodItem
Location
Route
Store
Vehicle
Warehouse
Launcher(Includes main method)
What I need to do next is: I have initialized an object called "Oatmeal" for the FoodItem class.
This FoodItem has 4 attributes as follows:
import java.time.LocalDate;
public class FoodItem {
public String label;
private double volume;
private double weight;
private LocalDate expirationDate;
The values for those attributes have been set in Launcher as follows:
FoodItem oatmeal = new FoodItem("Serving size is 1/2 Cup 40gr");
oatmeal.setVolume(25);
oatmeal.setWeight(0.500);
oatmeal.setExpirationDate(LocalDate.of(2025,2,5));
Now what I need to do is calculate the date to check if the product's expiration date is still valid with the logic of (Expiration Date - Today's Date + 3 Days) For that I've created a method called stillValid as follows:
import java.time.Period;
import java.util.Arrays;
import java.time.LocalDate;
private boolean stillValid(FoodItem foodItem){
LocalDate date = LocalDate.now();
LocalDate dayLeft = date.plus(Period.ofDays(3));
if(foodItem.getExpirationDate() != dayLeft) {
return true;
}
return false;
}
Now I need to use this method inside of my addItem method in order to check if the Item's expiration date is not passed, I can add to the store.
public void addItem(FoodItem foodItem) {
int stop = 0;
for (int i = 0; i < foodItemsArray.length; i++) {
if (foodItemsArray[i] != null) {
stop = 1;
break;
}
}
if (stop == 0) {
for (int i = 0; i < foodItemsArray.length; i++) {
if (foodItemsArray[i] != foodItem) {
foodItemsArray[i] = foodItem;
break;
}
}
}
}
In this part, I couldn't create the logic in my mind to have my stillValid fuction inside of addItem body, or even if I did the method stillValid correct.