我不知道是否曾经问过这个问题,但是我试图在发布之前找到答案,但是没有运气。
我有四个物体,分别是地板,冰箱,碗和苹果。根据需要添加冰箱,碗和苹果。
每个苹果都有一个有效期。
地板上盛着set<Fridge>
,冰箱里盛着set<bowl>
,碗里盛着set<apple>
。
当我向集合中添加一个苹果时,我想检索之前添加的最后一个苹果。
我尝试了以下代码,但由于它一直返回false,因此无济于事。
public boolean previousAppleExist(Date aDate){
boolean found = false;
Date previousDay = new Date(aDate.aPreviousDate(aDate)); //returns a day before
String expiryDate = previousDay.getDate();//returns a String in format dd/mm/yyyy
for(Fridge fridge: fridgeSet ){
if (this.fridgeExist(expiryDate)){
for (Bowl bowl: bowlSet){
if (this.existingFridge(expiryDate).bowlExist(expiryDate)){
for(Apple apple: appleSet){
if(this.existingFridge(expiryDate).
existingBowl(expiryDate).appleExist(expiryDate)){
found = true;
break;
}
else {
previousDay = new Date(previousDay.
aPreviousDate(previousDay));
startDate = previousDay.getDate();
}
}
}
else {
previousDay = new Date(previousDay.
aPreviousDate(previousDay));
expiryDate = previousDay.getDate();
}
}
break;
}
else {
previousDay = new Date(previousDay.aPreviousDate(previousDay));
expiryDate = previousDay.getDate();
}
}
return found;
}
我在做什么错了?