diff --git a/Answers/Library/.gitignore b/Answers/Library/.gitignore
new file mode 100644
index 0000000..f68d109
--- /dev/null
+++ b/Answers/Library/.gitignore
@@ -0,0 +1,29 @@
+### IntelliJ IDEA ###
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/Answers/Library/.idea/.gitignore b/Answers/Library/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/Answers/Library/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Answers/Library/.idea/.name b/Answers/Library/.idea/.name
new file mode 100644
index 0000000..4856afe
--- /dev/null
+++ b/Answers/Library/.idea/.name
@@ -0,0 +1 @@
+MyAPP.java
\ No newline at end of file
diff --git a/Answers/Library/.idea/inspectionProfiles/Project_Default.xml b/Answers/Library/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..41078ee
--- /dev/null
+++ b/Answers/Library/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/.idea/misc.xml b/Answers/Library/.idea/misc.xml
new file mode 100644
index 0000000..07115cd
--- /dev/null
+++ b/Answers/Library/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/.idea/modules.xml b/Answers/Library/.idea/modules.xml
new file mode 100644
index 0000000..26f9df2
--- /dev/null
+++ b/Answers/Library/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/.idea/uiDesigner.xml b/Answers/Library/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/Answers/Library/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/.idea/vcs.xml b/Answers/Library/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Answers/Library/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/Library.iml b/Answers/Library/Library.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/Answers/Library/Library.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/Library/src/Admin.java b/Answers/Library/src/Admin.java
new file mode 100644
index 0000000..0201834
--- /dev/null
+++ b/Answers/Library/src/Admin.java
@@ -0,0 +1,69 @@
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+public class Admin extends User{
+ String password;
+ static ArrayList adminArray = new ArrayList<>();
+ final String manegerPass = "DonNotHoldaGrudge";
+ public Admin(String C_name,String C_pass){
+ name=C_name;
+ password=C_pass;
+ }
+ public static void copyFileOnAdmin() {
+ try {
+
+ File admins = new File("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\admins.txt");
+ admins.createNewFile();
+ Scanner reader = new Scanner(admins);
+ while (reader.hasNextLine()) {
+ String[] copy = reader.nextLine().split("#");
+ Admin admin = new Admin(copy[0],copy[1]);
+ adminArray.add(admin);
+
+ }
+ reader.close();
+ } catch (Exception e) {
+ System.out.println("sorry");
+ }
+ }
+ public static void copyAdminOnFile() {
+ try {
+ FileWriter writer = new FileWriter("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\admins.txt");
+ for (int i=0 ; i< adminArray.size(); i++){
+ writer.write((adminArray.get(i).name)+"#"+(adminArray.get(i).password)+"\n");
+ writer.close();
+ }
+ } catch (IOException e) {
+ System.out.println("sorry");
+ throw new RuntimeException(e);
+ }
+
+
+ }
+ public static int getAdminID(String name){
+ for(int i=0 ; i< Admin.adminArray.size();i++){
+ if(Admin.adminArray.get(i).name.equals(name)){
+ return i ;
+ }
+ }
+ return (-1);
+ }
+ public static boolean checkAdminPass(int adminID, String adminPass){
+ if(Admin.adminArray.get(adminID).password.equals(adminPass)) {
+ return true;
+ }
+ return false;
+ }
+ public static boolean checkAdmins(String name){
+ for(int i=0; i booksArray = new ArrayList<>();
+ String title,author,subtitle;
+ int uniquebookID;
+ boolean availabilityStatus;
+ public Book(String C_title,String C_author,boolean C_availabilityStatus,String C_subtitle){
+ title=C_title;
+ author=C_author;
+ availabilityStatus=C_availabilityStatus;
+ subtitle=C_subtitle;
+ }
+
+ public static void copyFileOnBook() {
+ try {
+ File books = new File("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\books.txt");
+ books.createNewFile();
+ Scanner reader = new Scanner(books);
+ while (reader.hasNextLine()) {
+ String[] copy = reader.nextLine().split("#");
+ boolean status = false;
+ if (copy[2].equals("false")){
+ status = false;
+ }
+ else if (copy[2].equals("true")){
+ status = true;
+ }
+ Book book =new Book(copy[0],copy[1],status,copy[3]);
+ book.uniquebookID = Integer.parseInt(copy[4]);
+ Book.booksArray.add(book);
+ }
+ reader.close();
+ } catch (Exception e) {
+ System.out.println("sorry");
+ }
+ }
+ public static void copyBookOnFile() {
+ try {
+ FileWriter writer = new FileWriter("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\books.txt");
+ for (int i=0 ; i< booksArray.size(); i++){
+ writer.write((booksArray.get(i).title)+"#"+(booksArray.get(i).author)+"#");
+ if (booksArray.get(i).availabilityStatus){
+ writer.write("true"+"#");
+ }
+ else {
+ writer.write("false"+"#");
+ }
+ writer.write(booksArray.get(i).subtitle+"#"+booksArray.get(i).uniquebookID+"\n");
+ }
+
+ writer.close();
+ } catch (IOException e) {
+ System.out.println("sorry");
+ throw new RuntimeException(e);
+ }
+
+
+ }
+
+ public static void getAvailableBooks(){
+ System.out.println("Available books are : ");
+ for (int i =0 ; i< Book.booksArray.size();i++){
+ if(Book.booksArray.get(i).availabilityStatus){
+ System.out.println(Book.booksArray.get(i).title);
+ }
+ }
+
+
+ }
+
+ public static int getBookID(String title){
+ for(int i=0 ; i< Book.booksArray.size();i++){
+ if(Book.booksArray.get(i).title.equals(title)){
+ return i ;
+ }
+
+
+ }
+ return (-1);
+ }
+
+ public static boolean checkBookName(String name){
+ for(int i=0; i")){ counter++; }
+ if (counter != number){
+ return false;
+ }
+ return true;
+ }
+ public String editor(String sentens) {
+ String[] sen = sentens.split("");
+ String edit ="";
+ boolean check=false;
+ for(int i=0;i")){
+ check = !check;
+ }
+ if(sen[i].equals(">")){
+ edit=edit+"#";
+ }
+ if(check){
+ edit=edit+sen[i];
+ continue;
+ }
+ }
+ String res =edit.replace("<","");
+ return res;
+ }
+ public String getMassage (){
+ System.out.println("Enter your command : ");
+ massage = scan.nextLine();
+ return massage;
+ }
+ public boolean massageCompile ()
+ {
+ String[] compile = massage.split(" "); // maybe book name have space" "
+ if (!(compile[0].equals("lib"))){
+ System.out.println("wrong command.");
+ return false;
+ }
+ if((compile[1].equals("rent")) && (compile.length == 3)){
+ System.out.println("Sorry, I don't know who to rent the book to \nit's project bug");
+ return false;
+ }
+ switch (compile[1]){
+ case "add":
+ switch (compile[2]){
+ case "book":
+ if (!formatCheck(massage,6)){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ String[] choose = editor(massage).split("#");
+ if(Book.checkBookName(choose[0])){
+ System.out.println("There is a book with this name.\nPlease choose another name or give it a number");
+ return false;
+ }
+ Book book = new Book(choose[0],choose[1],true,choose[2]);
+ book.uniquebookID= Math.abs(rand.nextInt()%date.getSeconds());
+ Book.booksArray.add(book);
+ return true;
+ case "member":
+ if (!formatCheck(massage,4)){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ choose = editor(massage).split("#");
+ if(NormalUsers.checkUsers(choose[0])){
+ System.out.println("There is a user with this name.\nPlease choose another name");
+ return false;
+ }
+ Date today = new Date();
+ NormalUsers normalUsers = new NormalUsers(choose[0],choose[1],today.toString());
+ normalUsers.uniqueID = Math.abs(rand.nextInt()%date.getSeconds());
+ NormalUsers.normalUsersArray.add(normalUsers);
+ return true;
+ case "admin":
+ if (!formatCheck(massage,6)){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ choose = editor(massage).split("#");
+ if(Admin.checkAdmins(choose[0])){
+ System.out.println("There is a admin with this name.\nPlease choose another name");
+ return false;
+ }
+ Admin admin =new Admin(choose[0],choose[1]);
+ if (!choose[2].equals(admin.manegerPass)){
+ System.out.println("You do not have access to add admin");
+ return false;
+ }
+ Admin.adminArray.add(admin);
+ return true;
+
+
+ default:
+ System.out.println("wrong command.");
+ return false;
+
+ }
+ case "get":
+ switch (compile[2]){
+ case "hrs":
+ System.out.println("The library is active from 7:00 to 20:00 ");
+ return true;
+ case "available":
+ switch (compile[3]){
+ case "books":
+ Book.getAvailableBooks();
+ return true;
+ default:
+ System.out.println("wrong command.");
+ return false;
+ }
+ }
+ case "rent":
+ String password;
+ int userID,bookID ;
+ if (!formatCheck(massage,6)){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ String[] choose = editor(massage).split("#");
+ userID=NormalUsers.getUserID(choose[1]);
+ if (userID == (-1)){
+ System.out.println("The desired user was not found");
+ return false;
+ }
+ bookID = Book.getBookID(choose[0]);
+ if (bookID == (-1)){
+ System.out.println("The desired book was not found");
+ return false;
+ }
+ password = choose[2];
+ if(!(NormalUsers.checkPass(userID,password))){
+ System.out.println("The user's password is incorrect");
+ return false;
+ }
+ if(!(Rent.checkRent(bookID))){
+ System.out.println("The desired book has been rented");
+ return false;
+ }
+ Rent.rent(bookID,userID);
+ return true;
+
+ case "remove" :
+ switch (compile[2]){
+ case "member":
+ String name;
+ if (!formatCheck(massage,2)){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ choose = editor(massage).split("#");
+ name = choose[0];
+// String adminName = editor(compile[4]);
+// if(Admin.getAdminID(adminName) == (-1)){
+// System.out.println("The desired admin was not found");
+// return false;
+// } // :((((((((((
+// password = editor(compile[5]);
+// if(!(Admin.checkAdminPass(Admin.getAdminID(adminName),password))){
+// System.out.println("The admin's password is incorrect");
+// return false;
+// }
+ Rent.returnAllBooks(NormalUsers.getUserID(name));
+ NormalUsers.normalUsersArray.remove(NormalUsers.getUserID(name));
+ return true;
+ default:
+ System.out.println("wrong command.");
+ return false;
+ }
+
+
+ case "return" :
+ String bookName;
+ if (!formatCheck(massage,2) ){
+ System.out.println("wrong command.");
+ return false;
+ }
+ //
+ //
+ // we most make that defensive
+ //
+ //
+ choose = editor(massage).split("#");
+ bookName = choose[0];
+ if(Rent.returnRent(bookName)){
+ System.out.println("The return of the book was well done");
+ return true;
+ }
+ return false;
+ default:
+ System.out.println("wrong command.");
+ return false;
+
+
+ }
+
+
+
+ }
+}
diff --git a/Answers/Library/src/Library.java b/Answers/Library/src/Library.java
new file mode 100644
index 0000000..0b0de19
--- /dev/null
+++ b/Answers/Library/src/Library.java
@@ -0,0 +1,4 @@
+public class Library {
+ String libraryName = "merciful Aryaan";
+ int capacity = 1000;
+}
diff --git a/Answers/Library/src/MyAPP.java b/Answers/Library/src/MyAPP.java
new file mode 100644
index 0000000..072bafb
--- /dev/null
+++ b/Answers/Library/src/MyAPP.java
@@ -0,0 +1,49 @@
+import java.util.Scanner;
+
+public class MyAPP {
+ public static void main(String[] args) {
+ System.out.println("Hello, welcome to merciful Aryaan library\n");
+ System.out.println("You can use the following commands:\n");
+ System.out.println("- `lib add book `: Add a new book to the library.\n" +
+ "- `lib get hrs`: Retrieve library operating hours.\n" +
+ "- `lib rent `: Rent a book from the library.\n" +
+ "- `lib add member `: Add a new member to the library.\n" +
+ "- `lib rent `: Rent a book for a specific member.\n" +
+ "- `lib get available books`: View available books for rental.\n" +
+ "- `lib remove member `: Remove a member from the library (admin privilege required).\n" +
+ "- `lib return `: Return a rented book to the library.\n");
+ Scanner scan = new Scanner(System.in);
+ Book.copyFileOnBook();
+ Admin.copyFileOnAdmin();
+ NormalUsers.copyFileOnNormalUser();
+ Cli cli =new Cli();
+ lable:while (true) {
+ String massage = cli.getMassage();
+ if(massage.equals("exit")){
+ break lable;
+ }
+ if(cli.massageCompile()){
+ String answer;
+ while (true) {
+ System.out.println("do you have an other command ? y/n ");
+ answer = scan.next();
+ if (answer.equals("y")) {
+ continue lable;
+ } else if (answer.equals("n")) {
+ break lable;
+ } else {
+ System.out.println("wrong command.");
+ continue ;
+ }
+ }
+
+ }
+ }
+ System.out.println("Thank you for choosing our Library Management System. We're excited to provide you with an efficient and user-friendly platform for all your library needs. Happy reading!\n");
+ Book.copyBookOnFile();
+ Admin.copyAdminOnFile();
+ NormalUsers.copyNormalUserOnFile();
+ }
+
+
+}
diff --git a/Answers/Library/src/NormalUsers.java b/Answers/Library/src/NormalUsers.java
new file mode 100644
index 0000000..0c53bda
--- /dev/null
+++ b/Answers/Library/src/NormalUsers.java
@@ -0,0 +1,79 @@
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+public class NormalUsers extends User {
+ String registeryDate;
+ String password;
+ String rentBooks = "";
+ static ArrayList normalUsersArray = new ArrayList<>();
+ public NormalUsers(String C_name , String C_pass, String C_registryDate){
+ name=C_name;
+ password=C_pass;
+ registeryDate=C_registryDate;
+ }
+ public static void copyFileOnNormalUser() {
+ try {
+ File normalUsers = new File("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\normalUsers.txt");
+ normalUsers.createNewFile();
+ Scanner reader = new Scanner(normalUsers);
+ while (reader.hasNextLine()) {
+ String[] copy = reader.nextLine().split("#");
+ NormalUsers normalUser = new NormalUsers(copy[0],copy[1],copy[2]);
+ normalUser.uniqueID= Integer.parseInt(copy[3]);
+ for(int i=3 ; i< copy.length;i++){
+ normalUser.rentBooks = copy[i] + "#";
+ }
+ normalUsersArray.add(normalUser);
+ }
+ reader.close();
+ } catch (Exception e) {
+ System.out.println("sorry");
+ }
+ }
+ public static void copyNormalUserOnFile() {
+ try {
+ FileWriter writer = new FileWriter("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\normalUsers.txt");
+ for (int i=0 ; i< normalUsersArray.size(); i++){
+ writer.write((normalUsersArray.get(i).name)+"#"+(normalUsersArray.get(i).password)+"#"+normalUsersArray.get(i).registeryDate+"#"+normalUsersArray.get(i).uniqueID+"#");
+ for(int j=0; j< normalUsersArray.get(i).rentBooks.split("#").length;j++){
+ writer.write(normalUsersArray.get(i).rentBooks.split("#")[j]+"#");
+ }
+ writer.write("\n");
+ }
+ writer.close();
+ } catch (IOException e) {
+ System.out.println("sorry");
+ throw new RuntimeException(e);
+ }
+
+
+ }
+ public static int getUserID(String name){
+ for(int i=0 ; i< NormalUsers.normalUsersArray.size();i++){
+ if(NormalUsers.normalUsersArray.get(i).name.equals(name)){
+ return i ;
+ }
+
+
+ }
+ return (-1);
+ }
+ public static boolean checkPass(int userID, String userPass){
+ if(NormalUsers.normalUsersArray.get(userID).password.equals(userPass)) {
+ return true;
+ }
+ return false;
+ }
+ public static boolean checkUsers(String name){
+ for(int i=0; i rentArray = new ArrayList<>();
+ File rent = new File("C:\\Users\\MSI\\OneDrive\\Desktop\\Lib\\Library-Management-System\\Answers\\Library\\src\\rent.txt");
+ Scanner reader = new Scanner(rent);
+ while (reader.hasNextLine()) {
+ rentArray.add(reader.nextLine());
+ }
+ } catch (Exception e) {
+ System.out.println("sorry");
+ }
+ }
+ public static boolean checkRent(int bookID) {
+ return Book.booksArray.get(bookID).availabilityStatus;
+ }
+ public static boolean returnRent(String bookName){
+ int bookID=Book.getBookID(bookName);
+ if(bookID == (-1)){
+ System.out.println("The desired book was not found");
+ return false;
+ }
+ if (Book.booksArray.get(bookID).availabilityStatus){
+ System.out.println("This book had not been rented");
+ return false;
+ }
+ Book.booksArray.get(bookID).availabilityStatus = true;
+ for ( int i=0 ; i< NormalUsers.normalUsersArray.size() ;i++){
+ String[] rentbook = NormalUsers.normalUsersArray.get(i).rentBooks.split("#");
+ for (int j=0 ; j < rentbook.length ; j++){
+ if (rentbook[j].equals(bookName)){
+ NormalUsers.normalUsersArray.get(i).rentBooks = NormalUsers.normalUsersArray.get(i).rentBooks.replace(bookName,"");
+ return true;
+ }
+ }
+ }
+ System.out.println("eror rented book not found");
+ return false;
+ }
+
+ public static void returnAllBooks(int userID){
+ int rentbooks = NormalUsers.normalUsersArray.get(userID).rentBooks.split("#").length;
+ int rentedbooks = Book.booksArray.size();
+ for (int i=0 ; i< rentbooks ; i++){
+ for(int j=0 ; j< rentedbooks;j++){
+ if (NormalUsers.normalUsersArray.get(userID).rentBooks.split("#")[i].equals(Book.booksArray.get(j).title)){
+ Book.booksArray.get(j).availabilityStatus = true;
+ }
+ }
+ }
+ }
+}
+
diff --git a/Answers/Library/src/User.java b/Answers/Library/src/User.java
new file mode 100644
index 0000000..2b9fe68
--- /dev/null
+++ b/Answers/Library/src/User.java
@@ -0,0 +1,5 @@
+public class User {
+ String name;
+ int uniqueID;
+ String number;
+}