我一直在創造一個程序,就是添加搜索中刪除的預訂等等 小時後我finaly以爲我是在進步,但是當我刪除預訂我的程序找到正確的預訂返回該預訂的正確信息,但刪除不同的預訂。刪除數據的字符串從數組列表
我已經在一個zip附加的文件,就好像我顯示他們,他們會佔用大量的屏幕空間。該項目已取得BlueJay: hostelgreamenew.zip 18.4 KB
爲decleration代碼和對象添加到我的數組列表
public Hostel(String hostelName)
{
this.hostelName = "Newcastle Hostel";
bookings = new ArrayList<Booking>();
}
public String getHostelName()
{
return hostelName;
}
public String addBooking(String roomID, String roomType, String guest)
{
if (roomID.equals(""))
return "Error Please Entre Room ID";
else if (roomType.equals(""))
return "Error Please Entre Room Type";
else if (guest.equals(""))
return "Error Please Entre Guest Name";
bookings.add(new Booking(roomID,roomType,guest));
return "Room " + roomID + " " + roomType + " Has Been Booked For " + guest;
}
這是從我的宿舍類
public String deleteBooking(String roomID)
{
int index = 0;
for (Booking s : bookings)
{
if (s.getRoomID().equals(roomID))
{
//return "Room ID: " + roomID + " Room Type: " + s.getRoomType() + " Guest: " + s.getGuest();
String deleteMessage = "Room ID: " + roomID + " Room Type: " + s.getRoomType() + " Guest: " + s.getGuest();
int response = JOptionPane.showConfirmDialog(null, deleteMessage, "Confirm Delete",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.NO_OPTION)
{
} else if (response == JOptionPane.YES_OPTION)
{
bookings.remove(index);
}
index++;
}
}
return " Cannot find room";
}
這是取自取我的GUI類
else if (item.equals("Cancel Booking"))
{
newBookingButton.setEnabled(false);
cancelBookingButton.setEnabled(false);
String roomID = JOptionPane.showInputDialog(this, "Enter a room ID", "Delete a Booking", JOptionPane.QUESTION_MESSAGE);
output.setText(hostel.deleteBooking(roomID));
newBookingButton.setEnabled(true);
cancelBookingButton.setEnabled(true);
}
任何附加代碼n eeded要麼要求或存在以上感謝
這裏沒有人會下載zip文件,然後讀取所有的源代碼。請製作一個**最小**測試案例來說明問題(請參閱http://sscce.org)。 – 2012-01-07 17:34:52
修改的相關代碼現在顯示 – 2012-01-07 17:45:13
@HxMGraeme:請告訴我你的程序的起點,意思是說我必須在我的主要方法中寫入什麼來啓動它。而已 。 Regards – 2012-01-07 18:12:44