我已經寫了一個方法,根據每個房間的牀位是單人還是雙人,返回一個酒店的最大佔用率。方法沒有回覆正確總計
public int calcOccupancy() {
int total = 0;
Room roomref;
Bed bedref;
for (int x = 0; x < room.size(); x++){
roomref = room.get(x);
for (int y = 0; y < roomref.numBeds(); y++){
bedref = roomref.getBed(y);
switch(bedref.bedNum()){
case 1: total = total + 2;
case 2: total = total + 1;
default:break;
}
}
}
return total;
}
當我調用該方法,我似乎得到相當隨機值,雖然他們從不太遠了,他們應該是什麼。
任何人都可以弄清楚我做錯了什麼。如果需要,我可以從項目中提供更多的代碼。
在交換機中需要斷開語句。查看教程[這裏](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html) – CubeJockey