Skip to content

Commit

Permalink
fix CLI method
Browse files Browse the repository at this point in the history
  • Loading branch information
Homa-A committed May 17, 2024
1 parent 89a92ae commit a539f44
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 133 deletions.
3 changes: 1 addition & 2 deletions Answers/_40230112134/NormalUser.txt
Original file line number Diff line number Diff line change
@@ -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
192 changes: 65 additions & 127 deletions Answers/_40230112134/src/main/java/org/example/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,16 @@ 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");
normalUser.getPeople().remove(i);
break;
}
}
normalUser.setPeople(normalUser.getPeople());
}
public void ChapFileUser() {
for (int i = 0; i < normalUser.getPeople().size(); i++)
Expand All @@ -130,149 +127,90 @@ 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 <name> <author> <subtitle>");
System.out.println("lib get hrs");
System.out.println("lib rent <bookName>");
System.out.println("lib add member <studentID> <password>");
System.out.println("lib get available books");
System.out.println("lib get available users <password>");
System.out.println("7.lib remove member");
System.out.println("8.lib add member");
System.out.println("lib remove member <studentID> <password>");
System.out.println("lib return <bookName>");
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");
Expand Down
4 changes: 0 additions & 4 deletions Answers/_40230112134/src/main/java/org/example/MyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
14 changes: 14 additions & 0 deletions Answers/_40230112134/src/main/java/org/example/Rent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}

0 comments on commit a539f44

Please sign in to comment.