diff --git a/.gitignore b/.gitignore index a6bd609..04d233c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,8 @@ out/ .vscode/ .code-workspace + +students.json +books.json +categories.json +loans.json diff --git a/src/controller/LibraryController.java b/src/controller/LibraryController.java index a89e894..11cfa59 100644 --- a/src/controller/LibraryController.java +++ b/src/controller/LibraryController.java @@ -1,6 +1,8 @@ package controller; import data.FileDataModel; +import jsonlib.JSONSerializableFactory; + import java.util.List; import model.*; @@ -12,6 +14,13 @@ public class LibraryController { public LibraryController() { library = new Library(); fileDataModel = new FileDataModel(); + JSONSerializableFactory.registerType("UndergraduateStudent", UndergraduateStudent.class); + JSONSerializableFactory.registerType("GraduateStudent", GraduateStudent.class); + JSONSerializableFactory.registerType("Book", Book.class); + JSONSerializableFactory.registerType("Category", Category.class); + JSONSerializableFactory.registerType("Loan", Loan.class); + + loadData(); } public void addUndergraduateStudent(String studentId, String firstName, String lastName, String major, @@ -38,11 +47,14 @@ public List getAllStudents() { return library.getAllStudents(); } + public void addBook(String title, String author, String isbn, Category category, int publicationYear) { + Book book = new Book(title, author, isbn, category, publicationYear, false); + library.addBook(book); + } - public void addBook(String title, String author, String isbn,Category category, int publicationYear) { - Book book=new Book(title, author, isbn,category, publicationYear, false); - library.addBook(book); - + public void addCategory(String name, String description) { + Category category = new Category(name, description); + library.addCategory(category); } public void removeBook(String isbn) { @@ -74,14 +86,18 @@ public List getBorrowedBooksByStudent(String studentId) { return library.getBorrowedBooksByStudent(studentId); } - public List getBooksByCategory(String categoryName) { - return library.getBooksByCategory(categoryName); + public List getBooksByCategory(Category category) { + return library.getBooksByCategory(category); } public List getStudentsByMajor(String major) { return library.getStudentsByMajor(major); } + public List getCategories() { + return library.getCategories(); + } + public void saveData() { fileDataModel.saveBooks(library.getBooks()); fileDataModel.saveCategories(library.getCategories()); @@ -89,13 +105,11 @@ public void saveData() { fileDataModel.saveStudents(library.getAllStudents()); } - public void loadData() { library.setBooks(fileDataModel.loadBooks()); library.setCategories(fileDataModel.loadCategories()); library.setLoans(fileDataModel.loadLoans()); library.setStudents(fileDataModel.loadStudents()); - } } diff --git a/src/data/FileDataModel.java b/src/data/FileDataModel.java index 70cf146..07fca2a 100644 --- a/src/data/FileDataModel.java +++ b/src/data/FileDataModel.java @@ -66,7 +66,7 @@ public String readFromFile(String filePath) { try { content = String.join("\n", Files.readAllLines(Paths.get(filePath))); } catch (IOException e) { - e.printStackTrace(); + return null; } return content; @@ -74,6 +74,10 @@ public String readFromFile(String filePath) { public List loadFromFile(String filePath) { String content = readFromFile(filePath); + if (content == null) { + return new ArrayList<>(); + } + JSONParser parser = new JSONParser(content); JSONObject jsonObj = null; diff --git a/src/model/BaseModel.java b/src/model/BaseModel.java new file mode 100644 index 0000000..515f257 --- /dev/null +++ b/src/model/BaseModel.java @@ -0,0 +1,13 @@ +package model; + +import jsonlib.JSONSerializable; + +public abstract class BaseModel implements JSONSerializable { + public abstract String getDisplayName(); + + @Override + public abstract int hashCode(); + + @Override + public abstract boolean equals(Object obj); +} diff --git a/src/model/Book.java b/src/model/Book.java index efe639a..f241c47 100644 --- a/src/model/Book.java +++ b/src/model/Book.java @@ -1,11 +1,13 @@ package model; +import java.util.Objects; + import jsonlib.JSONSerializable; import jsonlib.JSONSerializableFactory; import jsonlib.types.JSONObject; import jsonlib.types.JSONDict; -public class Book implements JSONSerializable { +public class Book extends BaseModel { private String title; private String author; private String isbn; @@ -13,15 +15,14 @@ public class Book implements JSONSerializable { private int publicationYear; private boolean isBorrowed; - - -//Constructor - public Book(String title,String author,String isbn,Category category,int publicationYear,boolean isBorrowed){ - this.title=title; - this.author=author; - this.category=category; - this.isbn=isbn;this.publicationYear=publicationYear; - this.isBorrowed=isBorrowed; + // Constructor + public Book(String title, String author, String isbn, Category category, int publicationYear, boolean isBorrowed) { + this.title = title; + this.author = author; + this.category = category; + this.isbn = isbn; + this.publicationYear = publicationYear; + this.isBorrowed = isBorrowed; } // Setter @@ -30,7 +31,6 @@ public void borrowBook() { } public void returnBook() { - this.isBorrowed = false; } @@ -59,6 +59,17 @@ public boolean getIsBorrowed() { return this.isBorrowed; } + @Override + public String toString() { + return String.format("%s\n\tAuthor: %s\n\tCategory: %s\n\tISBN: %s\n\tPublication Year: %d\n\tAvailable: %s\n", + title, author, category, isbn, publicationYear, isBorrowed ? "No" : "Yes"); + } + + @Override + public String getDisplayName() { + return String.format("%s by %s (%s)", title, author, isbn); + } + @Override public JSONObject serialize() { JSONDict result = new JSONDict(); @@ -80,4 +91,23 @@ public static Book deserialize(JSONDict json) { category, json.getInteger("publicationYear"), json.getBoolean("isBorrowed")); } + @Override + public int hashCode() { + return Objects.hash(title, author, isbn, category, publicationYear, isBorrowed); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Book)) + return false; + + Book other = (Book) obj; + return this.title.equals(other.title) && this.author.equals(other.author) && this.isbn.equals(other.isbn) + && this.category.equals(other.category) && this.publicationYear == other.publicationYear + && this.isBorrowed == other.isBorrowed; + } } diff --git a/src/model/Category.java b/src/model/Category.java index 3640c68..163102a 100644 --- a/src/model/Category.java +++ b/src/model/Category.java @@ -1,10 +1,12 @@ package model; -import jsonlib.JSONSerializable; import jsonlib.types.JSONObject; + +import java.util.Objects; + import jsonlib.types.JSONDict; -public class Category implements JSONSerializable { +public class Category extends BaseModel { private String name; private String description; @@ -23,11 +25,21 @@ public String getDescription() { return this.description; } + @Override + public String toString() { + return String.format("%s (%s)", name, description); + } + + @Override + public String getDisplayName() { + return name; + } + @Override public JSONObject serialize() { JSONDict result = new JSONDict(); - result.put("class", JSONObject.fromString("Book")); + result.put("class", JSONObject.fromString("Category")); result.put("name", JSONObject.fromString(name)); result.put("description", JSONObject.fromString(description)); @@ -37,4 +49,23 @@ public JSONObject serialize() { public static Category deserialize(JSONDict json) { return new Category(json.getString("name"), json.getString("description")); } + + @Override + public int hashCode() { + return Objects.hash(name, description); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Category)) + return false; + + Category other = (Category) obj; + + return this.name.equals(other.name) && this.description.equals(other.description); + } } diff --git a/src/model/GraduateStudent.java b/src/model/GraduateStudent.java index c94f859..2303097 100644 --- a/src/model/GraduateStudent.java +++ b/src/model/GraduateStudent.java @@ -1,6 +1,9 @@ package model; import jsonlib.types.JSONObject; + +import java.util.Objects; + import jsonlib.types.JSONDict; public class GraduateStudent extends Student { @@ -38,6 +41,12 @@ public void setThesisTitle(String thesisTitle) { this.thesisTitle = thesisTitle; } + @Override + public String toString() { + return String.format("%s %s\n\tID: %s\n\tMajor: %s\n\tSupervisor: %s\n\tThesis Title: %s\n", firstName, lastName, + studentId, major, supervisor, thesisTitle); + } + @Override public JSONObject serialize() { JSONDict result = new JSONDict(); @@ -59,4 +68,25 @@ public static GraduateStudent deserialize(JSONDict json) { return new GraduateStudent(json.getString("studentId"), json.getString("firstName"), json.getString("lastName"), json.getString("major"), json.getString("supervisor"), json.getString("thesisTitle")); } + + @Override + public int hashCode() { + return Objects.hash(studentId, firstName, lastName, major, supervisor, thesisTitle); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof GraduateStudent)) + return false; + + GraduateStudent other = (GraduateStudent) obj; + + return this.studentId.equals(other.studentId) && this.firstName.equals(other.firstName) + && this.lastName.equals(other.lastName) && this.major.equals(other.major) + && this.supervisor.equals(other.supervisor) && this.thesisTitle.equals(other.thesisTitle); + } } diff --git a/src/model/Library.java b/src/model/Library.java index 93a090c..4432e76 100644 --- a/src/model/Library.java +++ b/src/model/Library.java @@ -31,12 +31,16 @@ public void addBook(Book book) { books.add(book); } + public void addCategory(Category category) { + categories.add(category); + } + public void removeBook(String isbn) { - for (Book book : books) { - if (book.getIsbn().equals(isbn)) { - books.remove(book); + for (int i = books.size() - 1; i >= 0; i--) + if (books.get(i).getIsbn().equals(isbn)) { + books.remove(i); + return; } - } } public Book searchBookByTitle(String title) { @@ -80,11 +84,11 @@ public void addStudent(Student student) { } public void removeStudent(String studentId) { - for (Student student : students) { - if (student.getStudentId().equals(studentId)) { - students.remove(student); + for (int i = students.size() - 1; i >= 0; i--) + if (students.get(i).getStudentId().equals(studentId)) { + students.remove(i); + return; } - } } public Student searchStudentById(String studentId) { @@ -121,13 +125,12 @@ public boolean borrowBook(Book book, Student student) { } public boolean returnBook(Book book) { - for (Loan loan : loans) { - if (loan.getBook().equals(book)) { - loans.remove(loan); - loan.getBook().returnBook(); + for (int i = loans.size() - 1; i >= 0; i--) + if (loans.get(i).getBook().equals(book)) { + loans.remove(i); return true; } - } + return false; } @@ -149,14 +152,14 @@ public List getCategories() { return this.categories; } - public List getBooksByCategory(String categoryName) { - List booksByCategory=new ArrayList<>(); - for(Book book : booksByCategory){ - if(book.getCategory().getName().equals(categoryName)){ - booksByCategory.add(book); - } + public List getBooksByCategory(Category category) { + List booksByCategory = new ArrayList<>(); + for (Book book : booksByCategory) { + if (book.getCategory().getName().equals(category.getName())) { + booksByCategory.add(book); } - return booksByCategory; + } + return booksByCategory; } diff --git a/src/model/Loan.java b/src/model/Loan.java index e654c3d..a124f05 100644 --- a/src/model/Loan.java +++ b/src/model/Loan.java @@ -1,14 +1,14 @@ package model; import java.util.Date; +import java.util.Objects; -import jsonlib.JSONSerializable; import jsonlib.JSONSerializableFactory; import jsonlib.types.JSONObject; import jsonlib.types.JSONDict; import jsonlib.types.JSONNumber; -public class Loan implements JSONSerializable { +public class Loan extends BaseModel { private Book book; private Student student; private Date loanDate; @@ -55,6 +55,11 @@ public Date getDueDate() { return this.dueDate; } + @Override + public String getDisplayName() { + return String.format("%s borrowed %s", student.getDisplayName(), book.getDisplayName()); + } + @Override public JSONObject serialize() { JSONDict result = new JSONDict(); @@ -78,4 +83,22 @@ public static Loan deserialize(JSONDict json) { return new Loan(book, student, new Date(loanDateValue.getValue()), new Date(dueDateValue.getValue())); } + @Override + public int hashCode() { + return Objects.hash(book, student, loanDate, dueDate); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Loan)) + return false; + + Loan other = (Loan) obj; + return this.student.equals(other.student) && this.book.equals(other.book) && this.loanDate.equals(other.loanDate) + && this.dueDate.equals(other.dueDate); + } } diff --git a/src/model/Student.java b/src/model/Student.java index 6a2e2ad..d35a7a7 100644 --- a/src/model/Student.java +++ b/src/model/Student.java @@ -1,8 +1,6 @@ package model; -import jsonlib.JSONSerializable; - -public abstract class Student implements JSONSerializable { +public abstract class Student extends BaseModel { protected String studentId; protected String firstName; protected String lastName; @@ -51,4 +49,8 @@ public String getMajor() { return this.major; } + @Override + public String getDisplayName() { + return String.format("%s %s (%s)", firstName, lastName, studentId); + } } diff --git a/src/model/UndergraduateStudent.java b/src/model/UndergraduateStudent.java index 4fa8990..e01057b 100644 --- a/src/model/UndergraduateStudent.java +++ b/src/model/UndergraduateStudent.java @@ -1,6 +1,9 @@ package model; import jsonlib.types.JSONObject; + +import java.util.Objects; + import jsonlib.types.JSONDict; public class UndergraduateStudent extends Student { @@ -27,6 +30,12 @@ public void setEnrollmentYear(int enrollmentYear) { this.enrollmentYear = enrollmentYear; } + @Override + public String toString() { + return String.format("%s %s\n\tID: %s\n\tMajor: %s\n\tEnrollment Year: %d\n", firstName, lastName, studentId, major, + enrollmentYear); + } + @Override public JSONObject serialize() { JSONDict result = new JSONDict(); @@ -47,4 +56,24 @@ public static UndergraduateStudent deserialize(JSONDict json) { json.getString("lastName"), json.getString("major"), json.getInteger("enrollmentYear")); } + @Override + public int hashCode() { + return Objects.hash(studentId, firstName, lastName, major, enrollmentYear); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof UndergraduateStudent)) + return false; + + UndergraduateStudent other = (UndergraduateStudent) obj; + + return this.studentId.equals(other.studentId) && this.firstName.equals(other.firstName) + && this.lastName.equals(other.lastName) && this.major.equals(other.major) + && this.enrollmentYear == other.enrollmentYear; + } } diff --git a/src/view/UserInterface.java b/src/view/UserInterface.java index 7286753..f8bdc0b 100644 --- a/src/view/UserInterface.java +++ b/src/view/UserInterface.java @@ -6,423 +6,458 @@ import controller.LibraryController; public class UserInterface { - private LibraryController libraryController; + private LibraryController libraryController; + private Scanner scanner; - public UserInterface() { - libraryController = new LibraryController(); - } + public UserInterface() { + libraryController = new LibraryController(); + scanner = new Scanner(System.in); + } - public void printMainMenu() { - System.out.println( - " ██╗ ██╗ ██████╗██████╗ ██╗ ██╗██████╗ \n"+ - "██████╗██████╗██████╗ ██║ ██║██╔════╝██╔══██╗ ██║ ██║██╔══██╗ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██║ ██║╚█████╗ ██████╦╝ ██║ ██║██████╦╝ ╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗ ██║ ██║ ╚═══██╗██╔══██╗ ██║ ██║██╔══██╗ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ║██████╔╝██████╔╝██████╦╝ ███████╗██║██████╦╝ ╚═════╝╚═════╝╚═════╝\n"+ - " ╚══════╝╚══════╝ ╚═════╝ ╚══════╝╚═╝╚═════╝ \n"+ - "███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗███╗ ███╗███████╗███╗ ██╗████████╗\n"+ - "████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝████╗ ████║██╔════╝████╗ ██║╚══██╔══╝\n"+ - "██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ██╔████╔██║█████╗ ██╔██╗██║ ██║ \n"+ - "██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██║╚██╔╝██║██╔══╝ ██║╚████║ ██║ \n"+ - "██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗██║ ╚═╝ ██║███████╗██║ ╚███║ ██║ \n"+ - "╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚══╝ ╚═╝ \n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Manage Users░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Manage Books░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➌)══> Loans ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➍)══> Reports ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Exit ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } + public void printMainMenu() { + System.out.println( + " ██╗ ██╗ ██████╗██████╗ ██╗ ██╗██████╗ \n" + + "██████╗██████╗██████╗ ██║ ██║██╔════╝██╔══██╗ ██║ ██║██╔══██╗ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██║ ██║╚█████╗ ██████╦╝ ██║ ██║██████╦╝ ╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗ ██║ ██║ ╚═══██╗██╔══██╗ ██║ ██║██╔══██╗ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ║██████╔╝██████╔╝██████╦╝ ███████╗██║██████╦╝ ╚═════╝╚═════╝╚═════╝\n" + + " ╚══════╝╚══════╝ ╚═════╝ ╚══════╝╚═╝╚═════╝ \n" + + "███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗███╗ ███╗███████╗███╗ ██╗████████╗\n" + + "████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝████╗ ████║██╔════╝████╗ ██║╚══██╔══╝\n" + + "██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ██╔████╔██║█████╗ ██╔██╗██║ ██║ \n" + + "██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██║╚██╔╝██║██╔══╝ ██║╚████║ ██║ \n" + + "██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗██║ ╚═╝ ██║███████╗██║ ╚███║ ██║ \n" + + "╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚══╝ ╚═╝ \n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> Manage Users░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> Manage Books░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(3)══> Loans ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(4)══> Reports ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Exit ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void printManageUsersMenu(){ - System.out.println( - " ███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗ \n"+ - "██████╗██████╗██████╗ ████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗ ██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗ ╚═════╝╚═════╝╚═════╝\n"+ - " ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ \n"+ - " ██╗ ██╗ ██████╗███████╗██████╗ ██████╗ \n"+ - "██████╗██████╗██████╗██████╗██║ ██║██╔════╝██╔════╝██╔══██╗██╔════╝██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝██║ ██║╚█████╗ █████╗ ██████╔╝╚█████╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗██████╗██║ ██║ ╚═══██╗██╔══╝ ██╔══██╗ ╚═══██╗██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝╚██████╔╝██████╔╝███████╗██║ ██║██████╔╝╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - " ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝ \n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Add Undergraduate Student░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Add Graduate Student ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➌)══> Search Student by ID ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➍)══> Remove Student by ID ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➎)══> List All Students ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Back to Main Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } + public void printManageUsersMenu() { + System.out.println( + " ███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗ \n" + + "██████╗██████╗██████╗ ████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗ ██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗ ╚═════╝╚═════╝╚═════╝\n" + + " ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ \n" + + " ██╗ ██╗ ██████╗███████╗██████╗ ██████╗ \n" + + "██████╗██████╗██████╗██████╗██║ ██║██╔════╝██╔════╝██╔══██╗██╔════╝██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝██║ ██║╚█████╗ █████╗ ██████╔╝╚█████╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗██████╗██║ ██║ ╚═══██╗██╔══╝ ██╔══██╗ ╚═══██╗██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝╚██████╔╝██████╔╝███████╗██║ ██║██████╔╝╚═════╝╚═════╝╚═════╝╚═════╝\n" + + " ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝ \n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> Add Undergraduate Student ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> Add Graduate Student ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(3)══> Search Student by ID ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(4)══> Remove Student by ID ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(5)══> List All Students ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Back to Main Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void printManageBooksMenu() { - System.out.println( - " ███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗ \n"+ - "██████╗██████╗██████╗ ████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗ ██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗ ╚═════╝╚═════╝╚═════╝\n"+ - " ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ \n"+ - " ██████╗ █████╗ █████╗ ██╗ ██╗ ██████╗ \n"+ - "██████╗██████╗██████╗██████╗██╔══██╗██╔══██╗██╔══██╗██║ ██╔╝██╔════╝ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝██████╦╝██║ ██║██║ ██║█████═╝ ╚█████╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗██████╗██╔══██╗██║ ██║██║ ██║██╔═██╗ ╚═══██╗ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝██████╦╝╚█████╔╝╚█████╔╝██║ ╚██╗██████╔╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - " ╚═════╝ ╚════╝ ╚════╝ ╚═╝ ╚═╝╚═════╝ \n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Add Book ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Remove Book by ISBN ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➌)══> Search Book ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➍)══> List All Available Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Back to Main Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"); - } + public void printManageBooksMenu() { + System.out.println( + " ███╗ ███╗ █████╗ ███╗ ██╗ █████╗ ██████╗ ███████╗ \n" + + "██████╗██████╗██████╗ ████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔════╝ ██╔════╝ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██╔████╔██║███████║██╔██╗██║███████║██║ ██╗ █████╗ ╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗ ██║╚██╔╝██║██╔══██║██║╚████║██╔══██║██║ ╚██╗██╔══╝ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██║ ╚═╝ ██║██║ ██║██║ ╚███║██║ ██║╚██████╔╝███████╗ ╚═════╝╚═════╝╚═════╝\n" + + " ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚══╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ \n" + + " ██████╗ █████╗ █████╗ ██╗ ██╗ ██████╗ \n" + + "██████╗██████╗██████╗██████╗██╔══██╗██╔══██╗██╔══██╗██║ ██╔╝██╔════╝ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝██████╦╝██║ ██║██║ ██║█████═╝ ╚█████╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗██████╗██╔══██╗██║ ██║██║ ██║██╔═██╗ ╚═══██╗ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝██████╦╝╚█████╔╝╚█████╔╝██║ ╚██╗██████╔╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + " ╚═════╝ ╚════╝ ╚════╝ ╚═╝ ╚═╝╚═════╝ \n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> Add Book ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> Remove Book by ISBN ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(3)══> Search Book ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(4)══> List All Available Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Back to Main Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void printSearchBookMenu(){ - System.out.println( - " ██████╗███████╗ █████╗ ██████╗ █████╗ ██╗ ██╗ \n"+ - "██████╗██████╗██████╗ ██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗██║ ██║ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ╚█████╗ █████╗ ███████║██████╔╝██║ ╚═╝███████║ ╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗ ╚═══██╗██╔══╝ ██╔══██║██╔══██╗██║ ██╗██╔══██║ ██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝ ██████╔╝███████╗██║ ██║██║ ██║╚█████╔╝██║ ██║ ╚═════╝╚═════╝╚═════╝\n"+ - " ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ \n"+ - " ██████╗ █████╗ █████╗ ██╗ ██╗ \n"+ - "██████╗██████╗██████╗██████╗ ██╔══██╗██╔══██╗██╔══██╗██║ ██╔╝ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝ ██████╦╝██║ ██║██║ ██║█████═╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - "██████╗██████╗██████╗██████╗ ██╔══██╗██║ ██║██║ ██║██╔═██╗ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝ ██████╦╝╚█████╔╝╚█████╔╝██║ ╚██╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - " ╚═════╝ ╚════╝ ╚════╝ ╚═╝ ╚═╝ \n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Search by Title ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Search by ISBN ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Back to Book Management ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" ); - } + public void printSearchBookMenu() { + System.out.println( + " ██████╗███████╗ █████╗ ██████╗ █████╗ ██╗ ██╗ \n" + + "██████╗██████╗██████╗ ██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗██║ ██║ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ╚█████╗ █████╗ ███████║██████╔╝██║ ╚═╝███████║ ╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗ ╚═══██╗██╔══╝ ██╔══██║██╔══██╗██║ ██╗██╔══██║ ██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝ ██████╔╝███████╗██║ ██║██║ ██║╚█████╔╝██║ ██║ ╚═════╝╚═════╝╚═════╝\n" + + " ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ \n" + + " ██████╗ █████╗ █████╗ ██╗ ██╗ \n" + + "██████╗██████╗██████╗██████╗ ██╔══██╗██╔══██╗██╔══██╗██║ ██╔╝ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝ ██████╦╝██║ ██║██║ ██║█████═╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + "██████╗██████╗██████╗██████╗ ██╔══██╗██║ ██║██║ ██║██╔═██╗ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝ ██████╦╝╚█████╔╝╚█████╔╝██║ ╚██╗ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + " ╚═════╝ ╚════╝ ╚════╝ ╚═╝ ╚═╝ \n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> Search by Title ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> Search by ISBN ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Back to Book Management ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void printLoanMenu(){ - System.out.println( - "██████╗██████╗██████╗██████╗ ██║ ██╗ ██╗██╗ ██╗████╗ ██╗ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝ ██║ ██║ ██║███████║██╔██╗██║ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - " ██║ ██║ ██║██╔══██║██║╚████║ \n"+ - "██████╗██████╗██████╗██████╗ ███████╗╚█████╔╝██║ ██║██║ ╚███║ ██████╗██████╗██████╗██████╗\n"+ - "╚═════╝╚═════╝╚═════╝╚═════╝ ╚══════╝ ╚════╝ ╚═╝ ╚═╝╚═╝ ╚══╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Check Out Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Return Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Back to Loan Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"); - } + public void printLoanMenu() { + System.out.println( + "██████╗██████╗██████╗██████╗ ██║ ██╗ ██╗██╗ ██╗████╗ ██╗ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝ ██║ ██║ ██║███████║██╔██╗██║ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + " ██║ ██║ ██║██╔══██║██║╚████║ \n" + + "██████╗██████╗██████╗██████╗ ███████╗╚█████╔╝██║ ██║██║ ╚███║ ██████╗██████╗██████╗██████╗\n" + + "╚═════╝╚═════╝╚═════╝╚═════╝ ╚══════╝ ╚════╝ ╚═╝ ╚═╝╚═╝ ╚══╝ ╚═════╝╚═════╝╚═════╝╚═════╝\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> Check Out Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> Return Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Back to Loan Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void printReportsMenu(){ - System.out.println( - " ██████╗ ███████╗██████╗ █████╗ ██████╗ ████████╗ ██████╗ \n"+ - "██████╗██████╗ ██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝ ██████╗██████╗\n"+ - "╚═════╝╚═════╝ ██████╔╝█████╗ ██████╔╝██║ ██║██████╔╝ ██║ ╚█████╗ ╚═════╝╚═════╝\n"+ - " ██╔══██╗██╔══╝ ██╔═══╝ ██║ ██║██╔══██╗ ██║ ╚═══██╗ \n"+ - "██████╗██████╗ ██║ ██║███████╗██║ ╚█████╔╝██║ ██║ ██║ ██████╔╝ ██████╗██████╗\n"+ - "╚═════╝╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═════╝\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➊)══> Check Out Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(➋)══> Return Books ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"+ - "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(⓿)══> Back to Loan Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░\n"); + public void printReportsMenu() { + System.out.println( + " ██████╗ ███████╗██████╗ █████╗ ██████╗ ████████╗ ██████╗ \n" + + "██████╗██████╗ ██╔══██╗██╔════╝██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝ ██████╗██████╗\n" + + "╚═════╝╚═════╝ ██████╔╝█████╗ ██████╔╝██║ ██║██████╔╝ ██║ ╚█████╗ ╚═════╝╚═════╝\n" + + " ██╔══██╗██╔══╝ ██╔═══╝ ██║ ██║██╔══██╗ ██║ ╚═══██╗ \n" + + "██████╗██████╗ ██║ ██║███████╗██║ ╚█████╔╝██║ ██║ ██║ ██████╔╝ ██████╗██████╗\n" + + "╚═════╝╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═════╝\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(1)══> List Books by Category ░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(2)══> List Books Borrowed by a Student ░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(3)══> List Students by Major ░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░(0)══> Back to Main Menu ░░░░░░░░░░░░░░░░░░░░░░░░░░\n" + + "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } + + public void displayMainMenu() { + while (true) { + printMainMenu(); + int choice = readIntInRange("Enter a number", 0, 4); + switch (choice) { + case 1: + displayMemberMenu(); + break; + case 2: + displayBookMenu(); + break; + case 3: + displayLoanMenu(); + break; + case 4: + displayReportMenu(); + break; + case 0: + libraryController.saveData(); + return; + default: + assert false : "UNREACHABLE"; + } } + } - public void displayMainMenu() { - while (true) { - printMainMenu();//Menu print - Scanner MainMenuInput = new Scanner(System.in);//Get input - int mainmenuinput = 0; - try { - mainmenuinput = MainMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (mainmenuinput) { - case 1: - displayMemberMenu(); - break; - case 2: - displayBookMenu(); - break; - case 3: - displayLoanMenu(); - break; - case 4: - displayReportMenu(); - break; - case 0: - return; - default: - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please select the correct option⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - break; - } + public void displayMemberMenu() { + while (true) { + printManageUsersMenu(); + int choice = readIntInRange("Enter a number", 0, 5); + switch (choice) { + case 1: { + String studentID = readString("Enter the Student ID"); + String firstName = readString("Enter the Student First Name"); + String lastName = readString("Enter the Student Last Name"); + String major = readString("Enter the Student Major"); + int enrollmentYear = readIntInRange("Enter the Student Enrollment Year", 1000, 3000); + libraryController.addUndergraduateStudent(studentID, firstName, lastName, major, enrollmentYear); + break; + } + case 2: { + String studentID = readString("Enter the Student ID"); + String firstName = readString("Enter the Student First Name"); + String lastName = readString("Enter the Student Last Name"); + String major = readString("Enter the Student Major"); + String supervisor = readString("Enter the Student Supervisor"); + String thesisTitle = readString("Enter the Student Thesis Title"); + libraryController.addGraduateStudent(studentID, firstName, lastName, major, supervisor, thesisTitle); + break; } + case 3: { + Student student = libraryController.searchStudent(readString("Enter Student ID")); + if (student == null) + System.out.println("Student not found!"); + else + System.out.println(student); + break; + } + case 4: { + String studentID = readString("Enter the Student ID"); + libraryController.removeStudent(studentID); + break; + } + case 5: + displayAllStudents(libraryController.getAllStudents()); + break; + case 0: + return; + default: + assert false : "UNREACHABLE"; + } } + } - public void displayMemberMenu() { - while (true) { - printManageUsersMenu(); - Scanner MemberMenuInput = new Scanner(System.in); - int membermenuinput = 0; - try { - membermenuinput = MemberMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (membermenuinput) { - case 1: - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ID║══> "); - String ugstudentId = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student First Name║══> "); - String ugfirstName = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student LastName║══> "); - String uglastName = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Major║══> "); - String ugmajor = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Enrollment Year║══> "); - int ugenrollmentyear = 0; - try{ - ugenrollmentyear = MemberMenuInput.nextInt(); - } - catch (Exception e){ - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - libraryController.addUndergraduateStudent(ugstudentId, ugfirstName, uglastName, ugmajor, ugenrollmentyear); - break; - case 2: - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ID║══> "); - String gstudentId = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student First Name║══> "); - String gfirstName = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student LastName║══> "); - String glastName = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Major║══> "); - String gmajor = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Supervisor║══> "); - String gsupervisor = MemberMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Thesis Title║══> "); - String gthesisTitle = MemberMenuInput.nextLine(); - libraryController.addGraduateStudent(gstudentId, gfirstName, glastName, gmajor, gsupervisor, gthesisTitle); - break; - case 3: - libraryController.searchStudent(getStudentIdForSearch()); - break; - case 4: - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ID║══> "); - String rstudentId = MemberMenuInput.nextLine(); - libraryController.removeStudent(rstudentId); - break; - case 5: - libraryController.getAllStudents(); - break; - case 0: - return; - default: - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please select the correct option⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - break; - } + public void displayBookMenu() { + while (true) { + printManageBooksMenu(); + int choice = readIntInRange("Enter a number", 0, 4); + switch (choice) { + case 1: { + String title = readString("Enter the title"); + String author = readString("Enter the author"); + String isbn = readString("Enter the ISBN"); + int publicationYear = readIntInRange("Enter the publication year", 1000, 3000); + List categories = libraryController.getCategories(); + Category category = readCategorySelection(categories); + libraryController.addBook(title, author, isbn, category, publicationYear); + break; } + case 2: { + String isbn = readString("Enter the ISBN"); + libraryController.removeBook(isbn); + break; + } + case 3: + displaySearchBookMenu(); + break; + case 4: + displayAllBooks(libraryController.getAvailableBooks()); + break; + case 0: + return; + default: + assert false : "UNREACHABLE"; + } } + } - public void displayBookMenu() { - while (true) { - printManageBooksMenu(); - Scanner BooksMenuInput = new Scanner(System.in); - int booksmenuinput = 0; - try { - booksmenuinput = BooksMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (booksmenuinput) { - case 1: - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Title║══> "); - String title = BooksMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Author║══> "); - String author = BooksMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ISBN║══> "); - String isbn1 = BooksMenuInput.nextLine(); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student Publication Year║══> "); - int publicationYear = BooksMenuInput.nextInt(); - // TODO: print list of available categories and let the user choose one or define one - libraryController.addBook(title, author, isbn1, null, publicationYear); - break; - case 2: - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ISBN║══> "); - String isbn2 = BooksMenuInput.nextLine(); - libraryController.removeBook(isbn2); - break; - case 3: - printSearchBookMenu(); - int searchbookmenu = 0; - try { - searchbookmenu = BooksMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (searchbookmenu){ - case 1: - libraryController.searchBookByTitle(getBookTitleForSearch()); - break; - case 2: - String isbn3; - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Book ISBN║══> "); - isbn3 = BooksMenuInput.nextLine(); - libraryController.searchBookByISBN(isbn3); - break; - case 0: - return; - } - break; - case 4: - libraryController.getAvailableBooks(); - break; - case 0: - return; - default: - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please select the correct option⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - break; - } - } + public void displaySearchBookMenu() { + printSearchBookMenu(); + int choice = readIntInRange("Enter a number", 0, 2); + switch (choice) { + case 1: { + Book book = libraryController.searchBookByTitle(readString("Enter Book Title")); + if (book == null) + System.out.println("Book not found!"); + else + System.out.println(book); + break; + } + case 2: { + String isbn = readString("Enter the book ISBN"); + Book book = libraryController.searchBookByISBN(isbn); + if (book == null) + System.out.println("Book not found!"); + else + System.out.println(book); + break; + } + case 0: + return; } - public void displayLoanMenu() { - while (true) { - printLoanMenu(); - Scanner loanMenuInput = new Scanner(System.in); - int loanmenuinput = 0; - try { - loanmenuinput = loanMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (loanmenuinput) { - case 1: - Book isbn4; - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Book ISBN║══> "); - Student SID; - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Book Student ID║══> "); - //libraryController.borrowBook(isbn4, SID); - break; - case 2: - Book isbn5; - //isbn5 = loanMenuInput.nextLine(); - //libraryController.returnBook(isbn5); - break; - case 0: - return; - default: - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please select the correct option⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - break; - } + } + + public void displayLoanMenu() { + while (true) { + printLoanMenu(); + int choice = readIntInRange("Enter a number", 0, 2); + switch (choice) { + case 1: { + String studentID = readString("Enter you Student ID"); + Student student = libraryController.searchStudent(studentID); + if (student == null) { + System.out.println("Student not found!"); + continue; + } + List availableBooks = libraryController.getAvailableBooks(); + if (availableBooks == null || availableBooks.size() == 0) { + System.out.println("No books available right now!"); + continue; + } + + Book selectedBook = readSelection("Which book do you want to borrow?", availableBooks); + libraryController.borrowBook(selectedBook, student); + break; } + case 2: { + String studentID = readString("Enter your Student ID"); + if (libraryController.searchStudent(studentID) == null) { + System.out.println("Student not found!"); + continue; + } + List books = libraryController.getBorrowedBooksByStudent(studentID); + if (books == null || books.size() == 0) { + System.out.println("You haven't borrowed any book!"); + continue; + } + Book selectedBook = readSelection("Which book do you want to return?", books); + libraryController.returnBook(selectedBook); + break; + } + case 0: + return; + default: + assert false : "UNREACHABLE"; + } } + } - public void displayReportMenu() { - while (true) { - printReportsMenu(); - Scanner reportsMenuInput = new Scanner(System.in); - int reportsmenuinput = 0; - try { - reportsmenuinput = reportsMenuInput.nextInt(); - } - catch(Exception e) { - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid character⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - } - switch (reportsmenuinput) { - case 1: - break; - case 2: - break; - case 0: - return; - default: - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please select the correct option⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░"); - System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); - break; - } + public void displayReportMenu() { + while (true) { + printReportsMenu(); + int choice = readIntInRange("Enter a number", 0, 3); + switch (choice) { + case 1: { + List categories = libraryController.getCategories(); + if (categories == null || categories.size() == 0) { + System.out.println("No categories available rightt now!"); + continue; + } + Category category = readSelection("Choose a category", categories); + List books = libraryController.getBooksByCategory(category); + if (books == null || books.size() == 0) { + System.out.println("No books available in this category"); + continue; + } + displayReport(books); + break; } - } + case 2: { + String studentID = readString("Enter your Student ID"); + if (libraryController.searchStudent(studentID) == null) { + System.out.println("Student not found!"); + continue; + } + List books = libraryController.getBorrowedBooksByStudent(studentID); + if (books == null || books.size() == 0) { + System.out.println("You haven't borrowed any book!"); + continue; + } + displayReport(books); + break; + } + case 3: { + String major = readString("Enter a major"); + List students = libraryController.getStudentsByMajor(major); + if (students == null || students.size() == 0) { + System.out.println("No students found in this major"); + continue; + } - public String getStudentIdForSearch() { - Scanner gSIFS = new Scanner(System.in); - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Student ID║══> "); - String sstudentId = gSIFS.nextLine(); - return sstudentId; + displayReport(students); + break; + } + case 0: + return; + default: + assert false : "UNREACHABLE"; + } } + } - public void getBookISBNForOperation() { - + public void displayAllStudents(List students) { + for (Student student : students) { + System.out.println(student); } + } - public String getBookTitleForSearch() { - Scanner gBTFS = new Scanner(System.in); - String T; - System.out.print("░░░░░░░░░░░░░░░░░░░░░░░░░░║Enter The Book Title║══> "); - T = gBTFS.nextLine(); - return T; + public void displayAllBooks(List books) { + for (Book book : books) { + System.out.println(book); } + } - public void getStudentIdForLoan() { - // TODO: Implement method 'getStudentIdForLoan'. - throw new UnsupportedOperationException("Unimplemented method 'getStudentIdForLoan'"); - } + public void displayReport(List results) { + for (int i = 0; i < results.size(); i++) + System.out.printf("%d. %s\n", i, results.get(i).getDisplayName()); + } - public void getBookISBNForLoan() { - // TODO: Implement method 'getBookISBNForLoan'. - throw new UnsupportedOperationException("Unimplemented method 'getBookISBNForLoan'"); - } + private void printPrompt(String prompt) { + System.out.print(String.format("░░░░░░░░░░░░░░░░░░░░░░░░░░║%s║══> ", prompt)); + System.out.flush(); + } - public void displayStudentDetails(Student student) { - // TODO: Implement method 'displayStudentDetails'. - throw new UnsupportedOperationException("Unimplemented method 'displayStudentDetails'"); - } + private void printInvalidInput() { + System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░<<<⚠⃨Please enter valid characters⚠⃨>>>░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + System.out.println("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░"); + } - public void displayBookDetails(Book book) { + private void clearScannerBuffer() { + if (scanner.hasNextLine()) + scanner.nextLine(); + } + private int readIntInRange(String prompt, int min, int max) { + while (true) { + printPrompt(prompt); + try { + int input = scanner.nextInt(); + clearScannerBuffer(); + if (input >= min && input <= max) + return input; + else { + printInvalidInput(); + continue; + } + } catch (Exception e) { + printInvalidInput(); + clearScannerBuffer(); + continue; + } } + } - public void getBookDetailsForCreation() { - // TODO: Implement method 'getBookDetailsForCreation'. - throw new UnsupportedOperationException("Unimplemented method 'getBookDetailsForCreation'"); - } - - public void displayLoanDetails(Loan loan) { - // TODO: Implement method 'displayLoanDetails'. - throw new UnsupportedOperationException("Unimplemented method 'displayLoanDetails'"); - } + private String readString(String prompt) { + printPrompt(prompt); + // TODO: validiate input + return scanner.nextLine(); + } - public void displayAllStudents(List students) { - System.out.println(); - } + private Category createNewCategory() { + String name = readString("Enter Category Name"); + String description = readString("Enter Category Description"); + libraryController.addCategory(name, description); + System.out.println("New category created successfully!"); + return readCategorySelection(libraryController.getCategories()); + + } + + private Category readCategorySelection(List categories) { + if (categories == null || categories.size() == 0) { + System.out.println("No categories available"); + System.out.println("Creating a new category..."); - public void displayAllBooks(List books) { - // TODO: Implement method 'displayAllBooks'. - throw new UnsupportedOperationException("Unimplemented method 'displayAllBooks'"); + return createNewCategory(); } - public void displayReport(List results) { + for (int i = 0; i < categories.size(); i++) + System.out.println(String.format("%d. %s", i, categories.get(i).getDisplayName())); + System.out.println(String.format("%d. %s", categories.size(), "Add new category")); + + int choice = readIntInRange("Choose an option", 0, categories.size()); + if (choice == categories.size()) + return createNewCategory(); + else + return categories.get(choice); + } + + private T readSelection(String prompt, List options) { + if (options == null || options.size() == 0) + return null; + + for (int i = 0; i < options.size(); i++) { + System.out.println(String.format("%d. %s", i, options.get(i).getDisplayName())); } + + return options.get(readIntInRange(prompt, 0, options.size() - 1)); + } }