In this excercise, you will design and implement a library management system. Th
ID: 3823632 • Letter: I
Question
In this excercise, you will design and implement a library management system. The library management system will be for an engineering school that has the following departments: Computer Engineering (CPEN), Electrical Engineering (ELEN), Industrial Engineering (IMEN), Mechanical Engineering (MEEN) and Civil Engineering (CIEN). The system will have the following requirements:
Each book has a title, author, ISBN number, number of pages, edition, publisher and engineering type (CPEN, ELEN, IMEN, MEEN or CIEN)
There are faculty accounts that have first name, last name, department, ID and position (adjunct professor, assistant professor, professor) and amount of borrowed books
There are student accounts that have first name, last name, ID, department and level (1, 2, 3 or 4) and amount of borrowed books
The library management system keeps track of books, and users by using files.
One file handles book information
One file handles user information
One file registers a name and a borrowed book.
There is a Registry class that holds a borrower’s ID and the ISBN number of the borrowed book.
Students of levels 1 and 2 can only borrow up to 3 books, students of levels 3 and 4 can borrow up to 5 books. Faculty can borrow up to 6 books.
When returning a book, you should input the amount of days the user held the book. The first 15 days are free, while extra days have a cost of $5.
The interface that you should use for this program is:
package projectinterface;
public interface LibraryInterface {
public void addBook(Book book);
public void addStudent(Student student);
public void addFaculty(Faculty faculty);
public void printBookInfo(String ISBN);
public void deleteBook(String ISBN);
public void deleteStudent(String ID);
public void deleteFaculty(String ID);
public boolean checkBookIsBorrowed(String ISBN);
public boolean checkStudentHasBooks(String ID);
public boolean checkFacultyHasBooks(String ID);
public void printAllBooks();
public void printAllBooksForPerson(String ID);
public void printAllBooksByDepartment(String department);
public void borrowBookToStudent(String ID, String ISBN);
public void borrowBookToFaculty(String ID, String ISBN);
public void returnBookFromStudent(String ID, String ISBN);
public void returnBookFromFaculty(String ID, String ISBN);
public void printBorrowedBookRegistry();
}
The program should have a menu that allows the following:
Add a new book
Add a new student
Add a Faculty
Search for information about a specific book (use ISBN)
Delete a book (use ISBN)
Check first if a user hasn’t borrowed the book
Delete a user from the system
Verify the user has returned all his books first
Show all books
Show all books for a specific user (use ID)
Show all books for a specific department
Borrow a book to a user
Return a book
Show every user and the books borrowed by user
Design constraints:
Inheritance: Student and Faculty classes extend the Person class.
Composition: Library class has:
ArrayList<Student>
ArrayList<Faculty>
ArrayList<Book>
ArrayList<Registry>
Interface: Library implements the provided LibraryInterface class.
Explanation / Answer
1. LibraryInterface
package projectinterface;
import library.Book;
import library.Faculty;
import library.Student;
public interface LibraryInterface {
public void addBook(Book book);
public void addStudent(Student student);
public void addFaculty(Faculty faculty);
public void printBookInfo(String ISBN);
public void deleteBook(String ISBN);
public void deleteStudent(String ID);
public void deleteFaculty(String ID);
public boolean checkBookIsBorrowed(String ISBN);
public boolean checkStudentHasBooks(String ID);
public boolean checkFacultyHasBooks(String ID);
public void printAllBooks();
public void printAllBooksForPerson(String ID);
public void printAllBooksByDepartment(String department);
public void borrowBookToStudent(String ID, String ISBN);
public void borrowBookToFaculty(String ID, String ISBN);
public void returnBookFromStudent(String ID, String ISBN);
public void returnBookFromFaculty(String ID, String ISBN);
public void printBorrowedBookRegistry();
}
2. Library
package library;
import java.util.ArrayList;
import projectinterface.LibraryInterface;
public class Library implements LibraryInterface {
private ArrayList<Student> studentList = new ArrayList<>();
private ArrayList<Faculty> facultyList = new ArrayList<>();
private ArrayList<Book> bookList = new ArrayList<>();
private ArrayList<Registry> registryList = new ArrayList<>();
public ArrayList<Student> getStudentList() {
return studentList;
}
public void setStudentList(ArrayList<Student> studentList) {
this.studentList = studentList;
}
public ArrayList<Faculty> getFacultyList() {
return facultyList;
}
public void setFacultyList(ArrayList<Faculty> facultyList) {
this.facultyList = facultyList;
}
public ArrayList<Book> getBookList() {
return bookList;
}
public void setBookList(ArrayList<Book> bookList) {
this.bookList = bookList;
}
public ArrayList<Registry> getRegistryList() {
return registryList;
}
public void setRegistryList(ArrayList<Registry> registryList) {
this.registryList = registryList;
}
@Override
public void addBook(Book book) {
// TODO Auto-generated method stub
this.bookList.add(book);
}
@Override
public void addStudent(Student student) {
// TODO Auto-generated method stub
this.studentList.add(student);
}
@Override
public void addFaculty(Faculty faculty) {
// TODO Auto-generated method stub
}
@Override
public void printBookInfo(String ISBN) {
// TODO Auto-generated method stub
for(int i = 0; i < bookList.size(); i++){
if(bookList.get(i).getISBN().equalsIgnoreCase(ISBN)){
System.out.println(bookList.get(i));
}
}
}
@Override
public void deleteBook(String ISBN) {
// TODO Auto-generated method stub
for(int i = 0; i < bookList.size(); i++){
if(bookList.get(i).getISBN().equalsIgnoreCase(ISBN)){
bookList.remove(i);
}
}
}
@Override
public void deleteStudent(String ID) {
// TODO Auto-generated method stub
for(int i = 0; i < studentList.size(); i++){
if(studentList.get(i).getID().equalsIgnoreCase(ID)){
studentList.remove(i);
}
}
}
@Override
public void deleteFaculty(String ID) {
// TODO Auto-generated method stub
}
@Override
public boolean checkBookIsBorrowed(String ISBN) {
// TODO Auto-generated method stub
for(int i = 0; i < registryList.size(); i++){
if(registryList.get(i).getISBN().equalsIgnoreCase(ISBN)){
return true;
}
}
return false;
}
@Override
public boolean checkStudentHasBooks(String ID) {
// TODO Auto-generated method stub
for(int i = 0; i < registryList.size(); i++){
if(registryList.get(i).getID().equalsIgnoreCase(ID)){
return true;
}
}
return false;
}
@Override
public boolean checkFacultyHasBooks(String ID) {
// TODO Auto-generated method stub
return false;
}
@Override
public void printAllBooks() {
// TODO Auto-generated method stub
for(int i = 0; i < bookList.size(); i++){
System.out.println(bookList.get(i).getTitle());
}
}
@Override
public void printAllBooksForPerson(String ID) {
// TODO Auto-generated method stub
for(int i = 0; i < registryList.size(); i++){
if(registryList.get(i).getID().equalsIgnoreCase(ID)){
System.out.println(registryList.get(i).getISBN());
}
}
}
@Override
public void printAllBooksByDepartment(String department) {
// TODO Auto-generated method stub
}
@Override
public void borrowBookToStudent(String ID, String ISBN) {
// TODO Auto-generated method stub
Registry reg = new Registry(ID, ISBN);
registryList.add(reg);
}
@Override
public void borrowBookToFaculty(String ID, String ISBN) {
// TODO Auto-generated method stub
}
@Override
public void returnBookFromStudent(String ID, String ISBN) {
// TODO Auto-generated method stub
for(int i = 0; i < registryList.size(); i++){
if(registryList.get(i).getID().equalsIgnoreCase(ID) || registryList.get(i).getISBN().equalsIgnoreCase(ISBN)){
registryList.remove(i);
}
}
}
@Override
public void returnBookFromFaculty(String ID, String ISBN) {
// TODO Auto-generated method stub
}
@Override
public void printBorrowedBookRegistry() {
// TODO Auto-generated method stub
for(int i = 0; i < registryList.size(); i++){
System.out.println(registryList.get(i).getID());
System.out.println(registryList.get(i).getISBN());
}
}
}
3. Student
package library;
public class Student{
//first name, last name, ID, department and level (1, 2, 3 or 4) and amount of borrowed books
public Student(String fName, String lName, String dept, String iD, String level, String amountBook) {
super();
this.fName = fName;
this.lName = lName;
this.dept = dept;
ID = iD;
this.level = level;
this.amountBook = amountBook;
}
private String fName;
private String lName;
private String dept;
private String ID;
private String level;
private String amountBook;
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public String getAmountBook() {
return amountBook;
}
public void setAmountBook(String amountBook) {
this.amountBook = amountBook;
}
}
3. Faculty:
package library;
public class Faculty{
//first name, last name, department, ID and position (adjunct professor, assistant professor, professor) and amount of borrowed books
private String fName;
private String lName;
private String dept;
private String ID;
private String position;
private String amountBook;
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
public String getlName() {
return lName;
}
public void setlName(String lName) {
this.lName = lName;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getAmountBook() {
return amountBook;
}
public void setAmountBook(String amountBook) {
this.amountBook = amountBook;
}
}
5. Book:
package library;
public class Book {
//title, author, ISBN number, number of pages, edition, publisher and engineering type (CPEN, ELEN, IMEN, MEEN or CIEN)
public Book(String title, String iSBN, String pages, String edition, String publisher, String engType) {
super();
this.title = title;
ISBN = iSBN;
this.pages = pages;
this.edition = edition;
this.publisher = publisher;
this.engType = engType;
}
private String title;
private String ISBN;
private String pages;
private String edition;
private String publisher;
private String engType;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public String getPages() {
return pages;
}
public void setPages(String pages) {
this.pages = pages;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getEngType() {
return engType;
}
public void setEngType(String engType) {
this.engType = engType;
}
}
6. Registry:
package library;
import java.util.HashMap;
import java.util.Map;
public class Registry {
//borrower’s ID and the ISBN number
private String ID;
private String ISBN;
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getISBN() {
return ISBN;
}
public void setISBN(String iSBN) {
ISBN = iSBN;
}
public Registry(String iD, String iSBN) {
super();
ID = iD;
ISBN = iSBN;
}
}
7. Driver:
package library;
import java.util.Scanner;
import projectinterface.LibraryInterface;
public class Driver {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* Add a new book Add a new student Add a Faculty Search for information
* about a specific book (use ISBN) Delete a book (use ISBN) Check first
* if a user hasn’t borrowed the book Delete a user from the system
* Verify the user has returned all his books first Show all books Show
* all books for a specific user (use ID) Show all books for a specific
* department Borrow a book to a user Return a book Show every user and
* the books borrowed by user
*/
LibraryInterface parentObject = new Library();
System.out.println("Please Chose: ");
System.out.println("1. Add a new book");
System.out.println("2. Add a new student");
System.out.println("3. Search for information about a specific book (use ISBN)");
System.out.println("4. Delete a book (use ISBN)");
System.out.println("5. Check first if a user hasn’t borrowed the book");
System.out.println("6. Delete a user from the system");
System.out.println("7. Verify the user has returned all his books first");
System.out.println("8. Show all books");
System.out.println("9. Show all books for a specific user (use ID)");
System.out.println("10. Show all books for a specific department");
System.out.println("11. Borrow a book to a user");
System.out.println("12. Return a book");
System.out.println("13. Show every user and the books borrowed by user");
System.out.println("14. Exit");
while (true) {
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch (choice) {
case 1: {
System.out.println(
"Enter details: title, author, ISBN number, number of pages, edition, publisher and engineering type (CPEN, ELEN, IMEN, MEEN or CIEN)::::");
String title = sc.nextLine();
String ISBN = sc.nextLine();
String pages = sc.nextLine();
String edition = sc.nextLine();
String publisher = sc.nextLine();
String engType = sc.nextLine();
Book book = new Book(title, ISBN, pages, edition, publisher, engType);
parentObject.addBook(book);
System.out.println("DONE");
break;
}
case 2: {
System.out.println("Enter details: first name, last name, ID, department and level (1, 2, 3 or 4) and amount of borrowed books::::");
String fName = sc.nextLine();
String lName = sc.nextLine();
String dept = sc.nextLine();
String ID = sc.nextLine();
String level = sc.nextLine();
String amountBook = sc.nextLine();
Student student = new Student(fName, lName, dept, ID, level, amountBook);
parentObject.addStudent(student);
System.out.println("DONE");
break;
}
case 3: {
System.out.println("Enter ISBN number::::");
String ISBN = sc.nextLine();
ISBN = sc.nextLine();
parentObject.printBookInfo(ISBN);
System.out.println("DONE");
break;
}
case 4:{
System.out.println("Enter ISBN number::::");
String ISBN = sc.nextLine();
ISBN = sc.nextLine();
parentObject.deleteBook(ISBN);
System.out.println("DONE");
break;
}
case 5:{
System.out.println("Enter ISBN number::::");
String ISBN = sc.nextLine();
ISBN = sc.nextLine();
boolean check = parentObject.checkBookIsBorrowed(ISBN);
System.out.println(check);
System.out.println("DONE");
break;
}
case 6:{
System.out.println("Enter ID::::");
String ID = sc.nextLine();
ID = sc.nextLine();
parentObject.deleteStudent(ID);
System.out.println("DONE");
break;
}
case 7:{
System.out.println("Enter ID::::");
String ID = sc.nextLine();
ID = sc.nextLine();
boolean check = parentObject.checkStudentHasBooks(ID);
System.out.println(check);
System.out.println("DONE");
break;
}
case 8:{
parentObject.printAllBooks();
System.out.println("DONE");
break;
}
case 9:{
System.out.println("Enter ID::::");
String ID = sc.nextLine();
ID = sc.nextLine();
parentObject.printAllBooksForPerson(ID);
System.out.println("DONE");
break;
}
/*case 10:{
System.out.println("Enter Department::::");
String department = sc.nextLine();
parentObject.printAllBooksByDepartment(department);
System.out.println("DONE");
break;
}*/
case 11:{
System.out.println("Enter ID and ISBN:");
String ID = sc.nextLine();
ID = sc.nextLine();
String ISBN = sc.nextLine();
parentObject.borrowBookToStudent(ID, ISBN);
System.out.println("DONE");
break;
}
case 12:{
System.out.println("Enter ID and ISBN:");
String ID = sc.nextLine();
ID = sc.nextLine();
String ISBN = sc.nextLine();
parentObject.returnBookFromStudent(ID, ISBN);
System.out.println("DONE");
break;
}
case 13:{
parentObject.printBorrowedBookRegistry();
System.out.println("DONE");
break;
}
case 14:{
System.out.println("EXITING");
System.exit(1);
break;
}
default:
System.out.println("Wrong Choice");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.