40 likes | 177 Views
Programming Fundamentals I Java Programming Spring 2009. Instructor: Xuan Tung Hoang tung_hx@icu.ac.kr TA: Tran Minh Trung trungtm@icu.ac.kt. Homework#4. Homework #4 (1): Encapsulation. Write a class, BookRec , to manage book’s information. Class BookRec contains:
E N D
Programming Fundamentals IJava Programming Spring 2009 Instructor: Xuan Tung Hoang tung_hx@icu.ac.kr TA: Tran Minh Trung trungtm@icu.ac.kt Homework#4
Homework #4 (1): Encapsulation • Write a class, BookRec, to manage book’s information. Class BookRec contains: • Properties (Instance variables): • title: String (title of a book) • id: int (identifier of a book) • amount: int ( number of copies of a book ) • Constructors • BookRec(String atitle, int anId, int anAmount) • BookRec(String atitle, int anId) • BookRec(BookRec aBookRec) • Set/Get methods for all above properties • getTitle(): String • setTitle( title: String ) • …
Homework #4 (2): Composition • Write a LibMan class that contains • A list of book records (array) • BookRec[] books • A constructor • LibMan(nBooks: int) • nBook is the number of book records that are managed • set methods: • void setBook(int pos, BookRec bRec ) • This method places a book record bRec in array books of LibMan at position pos • Get methods: • BookRec getBook(int pos) • This method gets a BookRec object at position pos from array books • BookRec getBookByID(int bookID) • This method searches a book record (in array books) whose idmatches bookID. If a book record is found, return it. Otherwise, return null.
Submission and Report • Due: 24th April, mid-night • Compress your source/class files into a ZIP file • Name the zip file according with the following template: • StudentID_labNumber.zip • Example: 20091004_lab4.zip • Submit the file to TA • Email address: submit.hw.code@gmail.com • Subject: “StudentID_ICE0124_lab4” • Example: 20061004_ICE0124_lab4