diff --git a/Answers/_40230112134/NormalUser.txt b/Answers/_40230112134/NormalUser.txt index ffd7292..9d11674 100644 --- a/Answers/_40230112134/NormalUser.txt +++ b/Answers/_40230112134/NormalUser.txt @@ -1,3 +1,2 @@ 40230112134/ad/84965/2024-05-17 -6//2/2024-05-17 -78456/asdf/8/2024-05-17 +56/adfsgd/98465/2024-05-17 diff --git a/Answers/_40230112134/src/main/java/org/example/Library.java b/Answers/_40230112134/src/main/java/org/example/Library.java index 4b69bda..3503d5b 100644 --- a/Answers/_40230112134/src/main/java/org/example/Library.java +++ b/Answers/_40230112134/src/main/java/org/example/Library.java @@ -108,11 +108,9 @@ public void AddNormalUser(String studentID) { WriteFileNormalUser("Normaluser.txt"); } public void DeleteNormalUser(String number) { - ReadFileNormalUser("NormalUser.txt"); for (int i = 0; i < normalUser.getPeople().size(); i++) { - String line1 = normalUser.getPeople().get(i); - String[] list = line1.split("/"); + String[] list = normalUser.getPeople().get(i).split("/"); if (Objects.equals(list[0], number)) { System.out.println("The deletion was successful"); @@ -120,7 +118,6 @@ public void DeleteNormalUser(String number) { break; } } - normalUser.setPeople(normalUser.getPeople()); } public void ChapFileUser() { for (int i = 0; i < normalUser.getPeople().size(); i++) @@ -130,9 +127,10 @@ public void ChapFileUser() { } } public void CLIComment() { + boolean flag = true; user.ReadFileBook("Book.txt"); ReadFileNormalUser("Normaluser.txt"); - while (true) { + while (flag) { System.out.println(getLibraryName() + " How can I help you???!!!"); System.out.println("lib add book "); System.out.println("lib get hrs"); @@ -140,139 +138,79 @@ public void CLIComment() { System.out.println("lib add member "); System.out.println("lib get available books"); System.out.println("lib get available users "); - System.out.println("7.lib remove member"); - System.out.println("8.lib add member"); + System.out.println("lib remove member "); + System.out.println("lib return "); System.out.println("lib exit"); - System.out.println("Enter your comment:"); + System.out.println("Enter your comment --->"); Scanner scanner = new Scanner(System.in); String comment = scanner.nextLine(); - String[] list = comment.split(" "); - if (Objects.equals(list[1], "add") && Objects.equals(list[2], "book")) - { - user.AddBook(list[3] , list[4] , list[5]); - } - else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "hrs")) + if (Objects.equals(comment, "") || Objects.equals(comment, " ")) { - System.out.println("**************************"); - System.out.println(getOperatingHours()); - System.out.println("**************************"); + flag = true; + continue; } - else if (Objects.equals(list[1], "exit")) { -// System.exit(0); - break; - } - else if (Objects.equals(list[1], "rent") && list.length <= 3) - { - Rent rent = new Rent(); - rent.RentBook(list[2]); + String[] list = comment.split(" "); + if (!(Objects.equals(list[0], "lib")) || list.length < 2) { + System.out.println("Invalid input. Please try again."); + flag = true; + continue; } - else if (Objects.equals(list[1], "add") && Objects.equals(list[2], "member")) + else { - if (Objects.equals(list[4], admin.getPassword())) + if (Objects.equals(list[1], "add") && Objects.equals(list[2], "book")) { - AddNormalUser(list[3]); + user.AddBook(list[3] , list[4] , list[5]); } - } - else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "available") && list.length == 3) - { - System.out.println("**************************"); - user.ChapFileBook(); - System.out.println("**************************"); - } - else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "available") && Objects.equals(list[4], admin.getPassword())) - { + else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "hrs")) + { + System.out.println("**************************"); + System.out.println(getOperatingHours()); + System.out.println("**************************"); + } + else if (Objects.equals(list[1], "exit")) { +// System.exit(0); + System.out.println("\nBye Bye"); + flag = false; + break; + } + else if (Objects.equals(list[1], "rent") && list.length <= 3) + { + Rent rent = new Rent(); + rent.RentBook(list[2]); + } + else if (Objects.equals(list[1], "add") && Objects.equals(list[2], "member")) + { + if (Objects.equals(list[4], admin.getPassword())) + { + AddNormalUser(list[3]); + } + } + else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "available") && Objects.equals(list[3], "books")) + { + System.out.println("**************************"); + user.ChapFileBook(); + System.out.println("**************************"); + } + else if (Objects.equals(list[1], "get") && Objects.equals(list[2], "available") && Objects.equals(list[4], admin.getPassword()) && Objects.equals(list[3], "users")) + { - System.out.println("**************************"); - ChapFileUser(); - System.out.println("**************************"); + System.out.println("**************************"); + ChapFileUser(); + System.out.println("**************************"); + } + else if (Objects.equals(list[1], "remove") && Objects.equals(list[2], "member")) + { + if (Objects.equals(list[4], admin.getPassword())) + { + DeleteNormalUser(list[3]); + } + } + else if (Objects.equals(list[1], "return")) + { + Rent rent = new Rent(); + rent.ReturnBook(list[2]); + } } -// switch (comment) -// { -// case "lib add book": -// if (BookCapacity <= getCapacityBook()) -// { -// BookCapacity++; -// user.AddBook(); -// } -// else -// { -// System.out.println("Sorry, we don't have room for books."); -// System.out.println("Try something else."); -// } -// CLIComment(); -// break; -// case 2: -// System.out.println(getOperatingHours()); -// CLIComment(); -// break; -// case 3: -// Rent rent = new Rent(); -// ChapFileBook(); -// System.out.println("Enter your ID you want to rent: "); -// String testId = scanner.nextLine(); -// rent.RentBook(testId); -// CLIComment(); -// break; -// case 4: -// boolean bb = getBookRepository(); -// if (!bb) -// { -// System.out.println("we do not have any books"); -// } -// CLIComment(); -// break; -// case 5: -// -// CLIComment(); -// break; -// case 6: -// ChapFileUser(); -// CLIComment(); -// break; -// case 7: -// String temp1 = scanner.nextLine(); -// if (Objects.equals(temp1, admin.getPassword())) -// { -// ChapFileUser(); -// System.out.println("Enter your ID you want delete : "); -// String testid = scanner.nextLine(); -// DeleteNormalUser(testid); -// } -// else -// { -// System.out.println("Sorry,Try something else."); -// } -// CLIComment(); -// break; -// case 8: -// if (UserCapacity < getCapacityUser()) -// { -// UserCapacity++; -// String temp = scanner.nextLine(); -// if (Objects.equals(temp, admin.getPassword())) -// { -// AddNormalUser(); -// } -// else -// { -// System.out.println("Sorry,Try something else."); -// } -// } -// else -// { -// System.out.println("Sorry, we don't have room for User"); -// System.out.println("Try something else."); -// } -// CLIComment(); -// break; -// case 9: -// System.out.println("Bye Bye"); -// System.exit(0); -// break; -// default: -// System.out.println("Try again"); -// break; -// }; } user.WriteFileBook("Book.txt"); WriteFileNormalUser("Normaluser.txt"); diff --git a/Answers/_40230112134/src/main/java/org/example/MyApp.java b/Answers/_40230112134/src/main/java/org/example/MyApp.java index 0fdc384..5314180 100644 --- a/Answers/_40230112134/src/main/java/org/example/MyApp.java +++ b/Answers/_40230112134/src/main/java/org/example/MyApp.java @@ -4,9 +4,5 @@ public class MyApp extends UniqueID{ public static void main(String[] args) { Library library = new Library(); library.CLIComment(); -// NormalUser normalUser = new NormalUser(); -// library.ReadFileNormalUser("NormalUser.txt"); -// library.AddNormalUser("40230112134"); -// library.WriteFileNormalUser("NormalUser.txt"); } } \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Rent.java b/Answers/_40230112134/src/main/java/org/example/Rent.java index bbbc7fd..aec59fa 100644 --- a/Answers/_40230112134/src/main/java/org/example/Rent.java +++ b/Answers/_40230112134/src/main/java/org/example/Rent.java @@ -31,4 +31,18 @@ public void RentBook(String name) { } } } + public void ReturnBook(String name) { + for (int i = 0; i < book.getTotal().size(); i++) + { + String[] list = book.getTotal().get(i).split("/"); + if (Objects.equals(list[1],name)) + { + book.getTotal().remove(i); + System.out.println("Thank you for returning the book"); + String temp = list[0] + "/" + list[1] + "/" + list[2] + "/" + list[3] + "/" + "true" ; + book.getTotal().add(temp); + break; + } + } + } } \ No newline at end of file