Csii Proj s25
Csii Proj s25
Group Members:
Write your Name and ID as shown above and the Names and ID numbers of your
group members.
Each student should upload this word document on Blackboard. However, only one
student in the group should upload the files that contain the Java code.
This project is about a library management system. It helps you to practice Inheritance,
Polymorphism, File and Exception handling in Java. It allows the user of your program to
manage a digital library, where he can add, remove, search, and store book information.
Define a Book class that serves as the base class. It should have a String title and
author. The Book class should have a constructor for initializing the title and
author. It should have a toString method that returns a string representation of the
Book object.
Define two subclasses, named EBook and PrintedBook. The EBook class should
have a fileSize, which is the size of the file in Megabytes.
The EBook and PrintedBook classes should have constructors. They should override
the toString method and return a string representation of the EBook and
PrintedBook object that includes the title and author.
Define a Library class. It should use ArrayList<Book> books to store the list of
all books in the library. It should have the method addBook(Book b) for adding a
Book object, a boolean removeBook(title) method for removing a book with
given title that returns true if the book was found and removed,
searchBook(title) that returns a reference to the Book object with a specific
title, or null if the book was not found, displayBooks() that displays all the
books in the library (one book on each line), readFromFile(String pathname)
that reads all the books from a file (one book should be read on each line), and
writeToFile(String pathname) that saves all the books in a file (one book
should be written on each line).
To display an EBook, start with letter E followed by the title then comma(,) then
author then comma(,) then the book size. The comma (,) separates the data fields
as shown below:
To display a PrintedBook, start with letter P followed by the title then comma(,)
then author then comma(,) then number of pages as shown below:
This is also how a book should be saved and read from a file. Each book should appear
on a separate line. Commas (,) are used to separate the data fields.
Write a displayMenu method that displays a menu to the user and returns his choice
as follows:
If the user enters 1 for his menu choice, then ask the user to enter the pathname of the file
to read, for example:
The src/books.txt file should store one book on each line. Any number of books
can be stored in the file.
If the user enters 2 for his menu choice, then ask the user to enter the book type (E or P),
title, author, size or pages depending on the book type. Create a new EBook or
PrintedBook object, depending on the book type, and add it to the ArrayList
object.
If the user enters 3, then ask the user to enter the title of the book that should be
removed. If the book was found and removed then display “Book was removed”.
Otherwise, display “Book was not found”.
If the user enters 4, then ask the user to enter the title of the book. If the book was
found then display the book information. Otherwise, display “Book was not
found”.
If the user enters 5, then display all the books in the ArrayList object on the screen.
Each book should be displayed on a separate line.
If the user enters 6, then ask the user to enter the pathname of the file, save all books in
the ArrayList object in the file on the disk and terminate the execution of the
program. Each book should be written on a separate line inside the file.
Upload all your program classes on Blackboard. Make sure that your program compiles
and runs properly. Otherwise, you will lose all the points on correctness. I will NOT fix
your program if the code does not compile or run correctly.