Computing programming
Object Orientated Development – Repeat Assignment 2018
(i) Items stored in a library can be either Books or DVDs. o Write a class called LibraryItem. Each library item should have a
unique ID, the year that the item was published and a variable indicating whether or not the item is out on loan at present.
o The ID of each library item should be of the form “L-2345”. The first item in the library should have an ID of “L-1”, the second item should have an ID of “L-2” and so on. This ID should be generated automatically each time a library item is created (i.e. the user should not have to enter a library item’s ID).
o Write a class to represent Books and a class to represent DVDs. Books and DVDs are both types of library items.
o A Book has an author, a title and an ISBN number. o A DVD has a title and a director. o All classes should provide access to their data fields using getter and
setter methods. o All classes should provide constructors which initialise each of the
data fields. o All classes should override the toString method so that it provides a
readable description of the object. o Provide equals methods for the Book and DVD classes. Two books are
the same if they have the same ISBN number. Two DVDs are the same if they have same title and director.
o The Book class should implement the Comparable interface. Books should be compared based on the respective ISBN numbers.
(40 marks, 4 marks each)
(ii) Write a class called LibraryCatalogue which stores LibraryItems in an array list. This class should have methods to:
o Add a new book to the catalogue given a title, author, ISBN and year published.
o Add a new DVD to the catalogue given a title, director and year published.
o Return the total number of library items in the catalogue o Return the number of library items which are out on loan o Remove a library item from the Catalogue given the ID
(20 marks, 4 each)
(iii) Write a class called LibraryMenu that contains the main method and gives the user the following options:
o Enter a new Book or a new DVD to the catalogue o Remove a library item from the catalogue given the ID o Print out details of all LibraryItems in the Catalogue o Print out the number of LibraryItems which are out on loan. o Close the program
(20 marks, 4 each)
(iv) If the user enters an invalid input the program should throw an InputMismatchException. The program should deal with any InputMismatchExceptions that are thrown by printing a message.
(10 marks)
(v) The program should continue running until the user selects the close option.
(10 marks)
• What do I submit?
(i) Submit the Book, DVD, LibraryItem, LibraryCatalogue and LibraryMenu java files.