-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClubFullException.ctxt
More file actions
6 lines (6 loc) · 1.92 KB
/
ClubFullException.ctxt
File metadata and controls
6 lines (6 loc) · 1.92 KB
1
2
3
4
5
6
#BlueJ class context
comment0.target=ClubFullException
comment0.text=\r\n\ \r\n\:\ FINAL\ QUESTION\:\ IF\ YOU\ WANTED\ TO\ USE\ AN\ EXCEPTION\ HOW\ WOULD\ YOU\ DO\ IT?\ \r\nWhat\ would\ you\ need\ to\ do\ in\ the\ calling\ method?\r\nEXPLAIN\ in\ DETAIL.\ ?\r\nThis\ class\ ClubFullException\ would\ be\ implemented\ in\ cases\ where\ the\ book\ club\ is\ full\r\nand\ a\ user\ would\ like\ to\ add\ another\ member,\ to\ avoid\ this\ we\ would\ have\ to\ remove\ an\ existing\r\nmember\ from\ the\ bookclub\ or\ increase\ the\ maximum\ amount\ of\ members\ allowed\ in\ the\ bookclub\r\n\r\n----------------------------------------------------------------------\r\n\ in\ the\ call\ method\ for\ ClubFullException\ I\ would\ add\ \r\n\r\n\ try\ {\r\n\ \ //\ Call\ the\ method\ that\ adds\ a\ new\ member\r\n\ \ bookClub.getMembersList().add(newMember);\r\n\r\n\r\n\r\n\ \ \ \ }\ catch\ (ClubFullException\ e)\ {\r\n\ \ \ \ System.out.println("Error\:\ "\ +\ e.getMessage());\r\n\ \ \ \ //\ Handle\ the\ exception\r\n\ \ \ \ //\ I\ would\ prompt\ the\ user\ to\ remove\ a\ member\ or\ increase\ the\ maximum\ members\r\n\ \ \ \ }\r\n\r\n\r\n\ \ \ \ ---------------------------------------------------------------------\r\n\ \ \ \ in\ the\ call\ method\ for\ the\ MenuInterface\ I\ would\ add\ \r\n\ \ \ \ in\ the\ case\ 1\ \:\ (adding\ a\ member\ case)\r\n\r\n\ \ \ \ if\ (bookClub.getMembersList().getTotal()\ >\=\ bookClub.maxNoOfMembers)\ {\r\n\ \ \ \ \ \ \ \ \ \ \ \ throw\ new\ ClubFullException("The\ book\ club\ is\ full.\ Cannot\ add\ more\ members.");\r\n\ \ \ \ \ \ \ \ }\r\n\r\n\ \ \ \ \ \ \ \ \ }\ catch\ (ClubFullException\ e)\ {\r\n\ \ \ \ \ \ \ \ System.out.println("Error\:\ "\ +\ e.getMessage());\r\n\ \ \ \ \ \ \ \ //\ Handle\ the\ exception\r\n\ \ \ \ \ \ \ \ //\ I\ would\ prompt\ the\ user\ to\ remove\ a\ member\ or\ increase\ the\ maximum\ members\r\n\ \ \ \ }\r\n\ \r\n
comment1.params=
comment1.target=ClubFullException()
numComments=2