Programming Fundamentals I Java Programming Spring 2009 Instructor: Xuan Tung Hoang TA: Tran Minh Trung Lab guide #5
XuanTung Hoang 2 LibMan - Project BookRec class -Title: String -ID: Int -Ammount: Int -Available: Int +setTitle(String title): void +getTitle(): String +setID(int ID): void +getID():int +setAmount(int anAmount):void +getAmmount():int +update(int n): void +getnAvailable():int LibMan class -libTitle: String -nBookshelves: Int -books: BookRecs +setTitle(String title): void +getTitle(): String +setnBookshelves (int n): void +getnBookshelves ():int +showLibInfo():void +addNewBook():void +placeBooktoBookshelf(int bookshe fID,BookRec bRec): void +bookStatus(int bookID):boolean +borrowBook(int bookID):void +returnBook(int bookID):void N 1 1 TestLibMan -option: int +main():void +showMenu():void +askOption():void
XuanTung Hoang 3 LibMan – new functions addNewBook() Add new book bookStatus(bookID) Available: Retuns true, Print out Title, # of books left Otherwise: Return false borrowBook(bookID) Check if the book is available or not If available then borrow, and update the # of books left Show again the updated status returnBook(bookID) Update the # books left Show again the updated status
XuanTung Hoang 4 LibMan – Template & requirements Links: Requirements Understand problem Understand the structure of template code Complete missed codes (fill in … area) Note: You can design your own program for solvi ng the problem
XuanTung Hoang 5 Templates & output examples TestLibMan.java C:\java TestLibMan ========== Main menu ======== 1. Show library information 2. Add new book 3. Show book's status 4. Borrow a book 5. Return a book ============================== Enter menu ID (1-5):
XuanTung Hoang 6 addNewBook() 2. Add new book Enter book's information: (1)Possition: 1 (2)(2) ID: 1 (3) Amount: 20 (4) Title: Java tutorial 2009
XuanTung Hoang 7 bookStatus(bookID) 3. Show book's status Enter book's ID: 1 Book title: Java tutorial 2009 Bookshelf ID: 1 Total amount: 20 Left amount: Show book's status Enter book's ID: 1 Book title: Java tutorial 2009 Bookshelf ID: 1 Total amount: 20 Left amount: 20
XuanTung Hoang 8 borrowBook(bookID) 4. Borrow a book Enter book's ID: 1 Book title: Java tutorial 2009 Bookshelf ID: 1 Total amount: 20 Left amount: 20 The book is borrowed successfully! Book title: Java tutorial 2009 Bookshelf ID: 1 Total amount: 20 Left amount: 19
XuanTung Hoang 9 returnBook(bookID) 5. Return a book Enter book's ID: 1 The book is returned successfully! Book title: Java tutorial 2009 Bookshelf ID: 1 Total amount: 20 Left amount: 20
XuanTung Hoang 10 Submission and Report Due: Right after lab time Compress your source/class files into a ZIP file Name the zip file according with the following template: StudentID_labNumber.zip Example: _lab4.zip Submit the file to TA address: Subject: “StudentID_ICE0124_lab4” Example: _ICE0124_lab4