diff --git a/Answers/40230112081/.idea/.gitignore b/Answers/40230112081/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/Answers/40230112081/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Answers/40230112081/.idea/40230112081.iml b/Answers/40230112081/.idea/40230112081.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/Answers/40230112081/.idea/40230112081.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/.idea/misc.xml b/Answers/40230112081/.idea/misc.xml
new file mode 100644
index 0000000..07115cd
--- /dev/null
+++ b/Answers/40230112081/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/.idea/modules.xml b/Answers/40230112081/.idea/modules.xml
new file mode 100644
index 0000000..4567373
--- /dev/null
+++ b/Answers/40230112081/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/.idea/uiDesigner.xml b/Answers/40230112081/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/Answers/40230112081/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/.idea/vcs.xml b/Answers/40230112081/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Answers/40230112081/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/Admins.txt b/Answers/40230112081/Admins.txt
new file mode 100644
index 0000000..25610e6
--- /dev/null
+++ b/Answers/40230112081/Admins.txt
@@ -0,0 +1,3 @@
+40230112081,Masoud,9121231234,admin,Masoud
+40230112081,Amir1,9120719012,admin,1234
+1234512345,krm,9112342345,admin,1234
diff --git a/Answers/40230112081/Book.java b/Answers/40230112081/Book.java
new file mode 100644
index 0000000..df05e3c
--- /dev/null
+++ b/Answers/40230112081/Book.java
@@ -0,0 +1,38 @@
+
+
+public class Book {
+ private String id;
+ private String title;
+ private String author;
+ private String description;
+ private String status;
+ private int existence;
+
+ // constructor
+ public Book(String id,String title,String author,String description,String status,int existence)
+ {
+ this.id = id;
+ this.title = title;
+ this.author = author;
+ this.description = description;
+ this.status = status;
+ this.existence = existence;
+ }
+
+ // getters
+ public String getId() { return this.id; }
+ public String getTitle() { return this.title; }
+ public String getAuthor() { return this.author; }
+ public String getDescription() { return this.description; }
+ public String getStatus() { return this.status; }
+ public int getExistence() { return this.existence; }
+
+ // setter
+ public void change_status(String new_stat) {
+ this.status = new_stat;
+ }
+
+ public void inc_existence(){
+ this.existence++;
+ }
+}
diff --git a/Answers/40230112081/Books.txt b/Answers/40230112081/Books.txt
new file mode 100644
index 0000000..516bdd1
--- /dev/null
+++ b/Answers/40230112081/Books.txt
@@ -0,0 +1,2 @@
+1,Math,Salehi,Calc,available,1
+3,Book1,Author1,Desc1,available,1
diff --git a/Answers/40230112081/Library.java b/Answers/40230112081/Library.java
new file mode 100644
index 0000000..b314da9
--- /dev/null
+++ b/Answers/40230112081/Library.java
@@ -0,0 +1,1063 @@
+import org.w3c.dom.ls.LSOutput;
+
+import java.io.ObjectStreamException;
+import java.sql.SQLOutput;
+import java.util.*;
+import java.text.SimpleDateFormat;
+import java.text.Format;
+
+public class Library {
+ private String libName;
+ private int libCap;
+ private String oprHours;
+
+ public Calendar cal;
+ public SimpleDateFormat simpleDate;
+
+ // repos & registries
+ public myFileCLass usersFileHandle;
+ public myFileCLass adminsFileHandle;
+ public myFileCLass booksFileHandle;
+ public myFileCLass rentalFileHandle;
+ // verifications
+ public Verifications v;
+ // constructor
+ public Library(String name, String duration, int cap){
+ this.oprHours = duration;
+ this.libCap = cap;
+ this.libName = name;
+ usersFileHandle = new myFileCLass();
+ adminsFileHandle = new myFileCLass();
+ booksFileHandle = new myFileCLass();
+ rentalFileHandle = new myFileCLass();
+ usersFileHandle.dir = "Users.txt";
+ adminsFileHandle.dir = "Admins.txt";
+ booksFileHandle.dir = "Books.txt";
+ rentalFileHandle.dir = "Rental.txt";
+ }
+ // getters
+ public String getLibName() { return this.libName; }
+ public int getLibCap() { return this.libCap; }
+ public String getOprHours() { return this.oprHours; }
+
+ public void adminEditPanel(User u){
+ String query;
+ String id, u_name, u_phone, pass;
+ id = u.getUserID();
+ u_name = u.getUser_name();
+ Scanner scn = new Scanner(System.in);
+ u_phone = u.getPhonenumber();
+ pass = u.getPassword();
+ String cmd;
+ v = new Verifications();
+ int flag = adminsFileHandle.getUsernameInFile().indexOf(u_name);
+ System.out.println("1. Username");
+ System.out.println("2. Phonenumber");
+ System.out.println("3. Password");
+ while (true){
+ System.out.println("choose to edit :");
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(Objects.equals(cmd, "Username") || Objects.equals(cmd, "1") || Objects.equals(cmd, "user") || Objects.equals(cmd, "usr")){
+ while(true){
+ System.out.println("Enter your new username :");
+ System.out.print(">>>");
+ u_name = scn.nextLine();
+ if(v.userUsernameValidator(u_name)){
+ if(!adminsFileHandle.getUsernameInFile().contains(u_name))
+ break;
+ else{
+ System.out.println("This username is already taken");
+ };
+ }
+ else{
+ System.out.println("Wrong format. try another :-|");
+ System.out.println("Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ }
+ }
+
+
+ query = u.getUserID()+","+u_name+","+u.getPhonenumber()+","+"admin"+","+u.getPassword();
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(flag), query);
+ break;
+ }
+ else if(Objects.equals(cmd, "Phonenumber") || Objects.equals(cmd, "2") || Objects.equals(cmd, "phone") || Objects.equals(cmd, "ph")){
+ while(true){
+ System.out.println("Enter your new phonenumber :");
+ System.out.print(">>>");
+ u_phone = scn.nextLine();
+ if(v.userPhonenumberValidator(u_phone)){
+ if(!adminsFileHandle.getPhoneNumbersInFile().contains(u_phone))
+ break;
+ else{
+ System.out.println("This phonenumber is already taken");
+ };
+ }
+ else{
+ System.out.println("Wrong format. try another :-|");
+ System.out.println("User phonenumber must start with any number instead of 0 with length 10");
+ }
+ }
+ query = u.getUserID()+","+u.getUser_name()+","+u_phone+","+"admin"+","+u.getPassword();
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(flag), query);
+ break;
+ }
+ else if(Objects.equals(cmd, "Password") || Objects.equals(cmd, "3") || Objects.equals(cmd, "pass") || Objects.equals(cmd, "pss")){
+ while(true){
+ System.out.println("Enter your new password :");
+ System.out.print(">>>");
+ pass = scn.nextLine();
+ if(v.userPasswordValidator(pass)){
+ break;
+ }
+ else{
+ System.out.println("Wrong format. try another :-|");
+ System.out.println("Password must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ }
+ }
+ query = u.getUserID()+","+u.getUser_name()+","+u.getPhonenumber()+","+"admin"+","+pass;
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(flag), query);
+ break;
+ }
+ else{
+ System.out.println("Wrong input");
+ }
+ }
+ }
+
+ public void add_normalUser(){ // sign-up just for normal users
+ String id, username, pass, phonenumber;
+ User u;
+ Scanner scn = new Scanner(System.in);
+ Scanner scn1 = new Scanner(System.in);
+ v = new Verifications();
+ // first string verification
+ System.out.println("Enter your id :");
+ System.out.println("Your id must be numerical with length between 10 and 15");
+ while (true){
+ id = scn.nextLine();
+ if(v.userIdValidator(id)){
+ if(!usersFileHandle.getIDInFile().contains(id) && !adminsFileHandle.getIDInFile().contains(id)){
+ break;
+ }
+ else{
+ System.out.println("This id is added to repository");
+ }
+ }
+ else{
+ System.out.println("Try again");
+ }
+ }
+
+ System.out.println("Enter user name");
+ while (true){
+ username = scn.nextLine();
+ if(v.userUsernameValidator(username)){
+ if(!usersFileHandle.getUsernameInFile().contains(username) && !adminsFileHandle.getUsernameInFile().contains(username)){
+ break;
+ }
+ else{
+ System.out.println("This username is already taken");
+ }
+ }
+ else{
+ System.out.println("Wrong format");
+ }
+ }
+
+ System.out.println("Enter a phonenumber");
+ while (true){
+ phonenumber = scn.nextLine();
+ if(v.userPhonenumberValidator(phonenumber)){
+ if(!usersFileHandle.getPhoneNumbersInFile().contains(phonenumber)){
+ break;
+ }
+ else{
+ System.out.println("this number is added before");
+ }
+ }
+ else{
+ System.out.println("Wrong format.");
+ }
+ }
+ System.out.println("Set a password");
+ while (true){
+ pass = scn.nextLine();
+ if(v.userPasswordValidator(pass)){
+ break;
+ }
+ else{
+ System.out.println("Wrong format");
+ }
+ }
+ u = new User(username, id, phonenumber, "normal", pass);
+ usersFileHandle.addUser(u);
+
+ }
+ // login as normal user
+ // login as admin user
+ public void login_normalUsers(){
+ String phone, pass, id, user;
+ v = new Verifications();
+ Scanner scn = new Scanner(System.in);
+ int flag;
+ if(usersFileHandle.lines_of_file().size() != 0){
+ while(true){
+ System.out.println("Enter your Username: (If you forget: type forget)");
+ user = scn.nextLine();
+ if(Objects.equals(user, "forget")) {
+ usersFileHandle.show_myUsername();
+ continue;
+ }
+ else if (v.userUsernameValidator(user) && usersFileHandle.getUsernameInFile().contains(user)) {
+ flag = usersFileHandle.getUsernameInFile().indexOf(user);
+ break;
+ }
+ else{
+ System.out.println("Username not found/wrong format, try again");
+ continue;
+ }
+ }
+ while (true){
+ System.out.println("Enter your password :(if you forget , type forget)");
+ pass = scn.nextLine();
+ if(Objects.equals(pass,"forget")){
+ usersFileHandle.show_myPassword();
+ continue;
+ } else if (v.userPasswordValidator(pass) && Objects.equals(pass, usersFileHandle.getUserPassword().get(flag))) {
+ break;
+ }
+ else{
+ System.out.println("Password not found/wrong format, try again");
+ continue;
+ }
+ }
+ User u = new User(user,usersFileHandle.getIDInFile().get(flag),usersFileHandle.getPhoneNumbersInFile().get(flag),"normal",pass);
+ normalUserPanel(u);
+ }
+ else{
+ System.out.println("There is no normal user in our repository, First sign up please. Thank you. :-)");
+ }
+
+ }
+ public boolean isLibOpen(){
+ String[] hoursParts = this.oprHours.split("-");
+ cal = Calendar.getInstance();
+ simpleDate = new SimpleDateFormat("hh:mm");
+ String date = simpleDate.format(cal.getTime());
+ char c = hoursParts[1].charAt(0);
+ int vclose = Integer.valueOf(c) - Integer.valueOf('0');
+ int close = vclose + 12;
+ char s = hoursParts[0].charAt(0);
+ int vopen =Integer.valueOf(s) - Integer.valueOf('0');
+ int start = vopen;
+ String[] current = date.split(":");
+ if(Integer.valueOf(current[0]) >= start && Integer.valueOf(current[0]) < close){
+ return true;
+ }
+
+
+ return false;
+ }
+ public void login_AdminUsers(){
+ String phone, pass, id, user;
+ v = new Verifications();
+ Scanner scn = new Scanner(System.in);
+ int flag;
+ if(adminsFileHandle.lines_of_file().size() != 0){
+ while(true){
+ System.out.println("Enter your Username: (If you forget: type forget)");
+ user = scn.nextLine();
+ if(Objects.equals(user, "forget")) {
+ adminsFileHandle.show_myUsername();
+ continue;
+ }
+ else if (v.userUsernameValidator(user) && adminsFileHandle.getUsernameInFile().contains(user)) {
+ flag = adminsFileHandle.getUsernameInFile().indexOf(user);
+ break;
+ }
+ else{
+ System.out.println("Username not found/wrong format, try again");
+ continue;
+ }
+ }
+ while (true){
+ System.out.println("Enter your password :(if you forget , type forget)");
+ pass = scn.nextLine();
+ if(Objects.equals(pass,"forget")){
+ adminsFileHandle.show_myPassword();
+ continue;
+ } else if (v.userPasswordValidator(pass) && Objects.equals(pass, adminsFileHandle.getUserPassword().get(flag))) {
+ break;
+ }
+ else{
+ System.out.println("Password not found/wrong format, try again");
+ continue;
+ }
+ }
+ User u = new User(user, adminsFileHandle.getIDInFile().get(flag), adminsFileHandle.getPhoneNumbersInFile().get(flag)
+ , "admin", pass);
+ adminUserPanel(u);
+ }
+ else{
+ System.out.println("There is no admin in our repository, It means, you have to signup as normal user");
+ }
+
+ }
+ public void show_helpMenuNormalUser(){
+ String cmd;
+ Scanner scn = new Scanner(System.in);
+ System.out.println("to add a book to library : lib add title author description(nonSpace description & brief)");
+ System.out.println("to Rent a book from library : lib rent your_id Book_id");
+ System.out.println("to Edit your phonenumber : user edit ph current_ph new_ph");
+ System.out.println("to Edit your username : user edit usr current_usr new_usr");
+ System.out.println("to Edit your password : user edit pss current_pss new_pss");
+ System.out.println("to Return a book : lib return book_id your_id");
+ System.out.println("to Show available books :lib show books");
+ System.out.println("to show your info/profile :user show profile");
+ System.out.println("to logout& close : enter close/exit");
+ System.out.println("to get back to your panel : Enter back");
+ while (true){
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(Objects.equals(cmd, "back") || Objects.equals(cmd, "Back"))
+ break;
+ else{
+ System.out.println("Wrong input : Try again.");
+ }
+ }
+ }
+ public void show_helpMenuAdmins(){
+ Scanner scn = new Scanner(System.in);
+ String cmd;
+ System.out.println("to add book : lib add book_title book_author book_desc"); // done
+ System.out.println("to edit normal user : lib edit (ph/pss/usr) current new_one (usr : username, pss:password, ph : phonenumber"); // done
+ System.out.println("to remove user : lib remove user user_id user_name user_phone"); // done
+ System.out.println("to remove book : lib remove book book_title book_author book_desc"); // done
+ System.out.println("to remove rent : lib remove rental_date user_id book_id (Attention : enter date in day/Month/year , use month full_name)");
+ System.out.println("to promote normal user : user promote user_id user_name user_phone"); // done
+ System.out.println("to show users : lib show users"); // done
+ System.out.println("to show books : lib show books (-A : all books , -E : only available books , -R : in-rent books)"); // done
+ System.out.println("to show rents : lib show rents"); // done
+ System.out.println("to exit your panel : back to your panel"); // done
+ System.out.println("to edit your profile :lib edit admin"); // done
+ System.out.println("***Attention*** : avoid to enter space more than one , avoid to enter any character, Each command must be space separated");
+ System.out.println("for entering space in each field : use underline character '_' ");
+ System.out.println("to back to your panel from this menu : just enter back");
+ while (true){
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if (Objects.equals(cmd, "back")){
+ break;
+ }
+ else{
+ System.out.println("Just enter back. :-|");
+ }
+ }
+ }
+ public void normalUserPanel(User u){
+ cal = Calendar.getInstance();
+ simpleDate = new SimpleDateFormat("dd/MMMM/yyyy");
+ String date = simpleDate.format(cal.getTime());
+ v = new Verifications();
+ String cmd;
+ String p1,p2, u1,u2, ps1,ps2;
+ String query;
+ ArrayList list;
+ Scanner scn = new Scanner(System.in);
+ System.out.println("*******************************************************************");
+ System.out.println("Welcome to your panel " + u.getUser_name() + " :");
+ System.out.println("Library is open in :" + this.oprHours);
+ while (true) {
+ System.out.println("Print help to get help with your commands :(Normal user privileges)");
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(Objects.equals(cmd, "help") || Objects.equals(cmd, "Help") || cmd.contains("help")){
+ show_helpMenuNormalUser();
+ } else if (Objects.equals(cmd ,"close") || Objects.equals(cmd, "exit")) {
+ break;
+
+ } else if((cmd.contains("lib") || cmd.contains("user")) && !cmd.contains("*")){
+ list = v.get_SectionsPanelQuery(cmd);
+ if(Objects.equals(list.get(1), "add")){
+ try {
+ // add book
+ String title, auth, desc;
+ title = list.get(2);
+ auth = list.get(3);
+ desc = list.get(4);
+ if(booksFileHandle.getAuthorsFromFileBook().contains(auth) && booksFileHandle.getTitlesFromFileBook().contains(title) &&
+ booksFileHandle.getDescriptionsFromFileBook().contains(desc)){
+ // inc existence
+ System.out.println("This book is added before.");
+ int i = booksFileHandle.getAuthorsFromFileBook().indexOf(auth);
+ String new_exst = String.valueOf(Integer.valueOf(booksFileHandle.getExistsFromFileBook().get(i))+1);
+ query = booksFileHandle.getIdFromFileBook().get(i) + "," +booksFileHandle.getTitlesFromFileBook().get(i)+","+
+ booksFileHandle.getAuthorsFromFileBook().get(i)+","+booksFileHandle.getDescriptionsFromFileBook().get(i)+","+
+ "available,"+new_exst;
+ booksFileHandle.editLineInFile(booksFileHandle.lines_of_file().get(i), query);
+ }
+ else{
+ // add a new book
+ String id = String.valueOf(booksFileHandle.set_id()+1);
+ String existence = "1";
+ query = id+","+title+","+auth+","+desc+","+"available,"+existence;
+ booksFileHandle.add_to_file(query);
+ System.out.println("Book is added successfully.");
+ }
+ }catch (Exception e){
+ System.out.println("Missing args, Try command in correct way.");
+ }
+ }
+ else if(Objects.equals(list.get(1), "rent")){
+ try{
+ // layer 1 : check availability user_id
+ // layer 2 : " " book_id
+ // layer 3 : " " rentQuery
+ String id = list.get(3);
+ String user_ID = list.get(2);
+ int i = booksFileHandle.getIdFromFileBook().indexOf(id);
+ int f;
+ String rentQuery = date + ","+ user_ID+","+id;
+ if(usersFileHandle.getIDInFile().contains(user_ID)){
+ if(booksFileHandle.getIdFromFileBook().contains(id)){
+ if(!rentalFileHandle.lines_of_file().contains(rentQuery)){
+ rentalFileHandle.add_to_file(rentQuery);
+ booksFileHandle.change_status_inFileRent(id);
+ System.out.println("Rent is done !. :-)");
+ }
+ else{
+ System.out.println("This rent request is active at this time. Try another book.");
+ }
+ }
+ else{
+ System.out.println("This book id is not available in book repository. :-|");
+ }
+ }
+ else{
+ System.out.println("This user ID is not available in user repository. :-|");
+ }
+ }catch (Exception e){
+ System.out.println("Missing args, apply command in correct way.");
+ }
+
+
+ }
+ else if(Objects.equals(list.get(1), "edit")){
+ // edit your info
+ try{
+ if(Objects.equals(list.get(2), "ph")){
+ // edit phonenumber
+ p1 = list.get(3);
+ p2 = list.get(4);
+ while(true){
+ if(v.userPhonenumberValidator(p2)){
+ break;
+ }
+ else{
+ System.out.println("Enter valid username .");
+ System.out.println("User phonenumber must start with any number instead of 0 with length 10");
+ p2 = scn.nextLine();
+ }
+ }
+ while (true){
+ if(!usersFileHandle.getPhoneNumbersInFile().contains(p2))
+ break;
+ else{
+ System.out.println("This phonenumber is already taken . try another one");
+ System.out.print(">>>");
+ p2 = scn.nextLine();
+ }
+ }
+
+ int i = usersFileHandle.getPhoneNumbersInFile().indexOf(p1);
+ if(Objects.equals(p1, u.getPhonenumber())){
+ query = usersFileHandle.getIDInFile().get(i)+","+
+ usersFileHandle.getUsernameInFile().get(i)+","+p2+",normal,"+usersFileHandle.getUserPassword().get(i);
+ usersFileHandle.editLineInFile(usersFileHandle.lines_of_file().get(i), query);
+ System.out.println("phonenumber has been updated");
+ }
+ else{
+ System.out.println("Repeat your command, your current phonenumber is not correct in input. ");
+ }
+
+ }
+ else if(Objects.equals(list.get(2), "usr")){
+ u1 = list.get(3);
+ u2 = list.get(4);
+ while(true){
+ if(v.userUsernameValidator(u2)){
+ break;
+ }
+ else{
+ System.out.println("Enter valid username .");
+ System.out.println("Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ u2 = scn.nextLine();
+ }
+ }
+ while (true){
+ if(!usersFileHandle.getUsernameInFile().contains(u2))
+ break;
+ else{
+ System.out.println("This username is already taken . try another one");
+ System.out.print(">>>");
+ u2 = scn.nextLine();
+ }
+ }
+ int i = usersFileHandle.getUsernameInFile().indexOf(u1);
+ if(Objects.equals(u1, u.getUser_name())){
+ query = usersFileHandle.getIDInFile().get(i)+","+
+ u2+","+usersFileHandle.getPhoneNumbersInFile().get(i)+",normal,"+usersFileHandle.getUserPassword().get(i);
+ usersFileHandle.editLineInFile(usersFileHandle.lines_of_file().get(i), query);
+ u.set_new_username(u2);
+ System.out.println("Your username has been updated");
+ }
+ else{
+ System.out.println("Repeat your command, your current username is not correct in input. ");
+ }
+
+ }
+ else if(Objects.equals(list.get(2), "pss")){
+ p1 = list.get(3);
+ p2 = list.get(4);
+ while (true){
+ if(v.userPasswordValidator(p2)){
+ break;
+ }
+ else{
+ System.out.println("Wrong format, try another password.");
+ }
+ }
+
+ if(!Objects.equals(p1, u.getPassword())){
+ System.out.println("Try command again, current password is not correct.");
+ }
+ else{
+ int i = usersFileHandle.getUserPassword().indexOf(p1);
+ query = usersFileHandle.getIDInFile().get(i)+"," + usersFileHandle.getUsernameInFile().get(i)+","+
+ usersFileHandle.getPhoneNumbersInFile().get(i) + ",normal,"+p2;
+ usersFileHandle.editLineInFile(usersFileHandle.lines_of_file().get(i), query);
+ System.out.println("Your password has been updated.");
+ }
+
+ }
+ }catch (Exception e){
+ System.out.println("Missing args, Apply command in correct way.");
+ }
+ }
+ else if(Objects.equals(list.get(1), "return")){
+ try {
+ // lib return id your_id
+ int flag;
+ String bookId = list.get(2), user_id = list.get(3);
+ // edit booksFile : repository // change status if 0 existence or increment existence
+ // edit rentals
+
+ String rent_Query = "";
+ for(String line : rentalFileHandle.lines_of_file()){
+ if(line.contains(user_id+","+bookId)){
+ rent_Query = rentalFileHandle.getDate_fromSingleLine(line) + "," + user_id+","+bookId;
+ break;
+ }
+ }
+
+ if(!Objects.equals(rent_Query, "")){
+ rentalFileHandle.editLineInFile(rent_Query, "");
+ booksFileHandle.change_status_inFileReturnCase(bookId);
+ }
+ else{
+ System.out.println("This rental is not available in rents repository. :-|");
+ }
+ }catch (Exception e){
+ System.out.println("Missing args, Apply command in correct way.");
+ }
+
+
+
+ }
+ else if(Objects.equals(list.get(1), "show")){
+ try{
+ if(Objects.equals(list.get(2), "profile") || Objects.equals(list.get(2), "Profile")){
+ System.out.println("User_id : " + u.getUserID());
+ System.out.println("User_name : "+u.getUser_name());
+ System.out.println("User_phone : "+u.getPhonenumber());
+ System.out.println("Access level : "+u.getRole());
+ }
+ else if(Objects.equals(list.get(2), "Books") || Objects.equals(list.get(2), "books") || Objects.equals(list.get(2), "book")){
+ for(int i = 0;i < booksFileHandle.getStatsFromFileBook().size();i++){
+ if(Objects.equals(booksFileHandle.getStatsFromFileBook().get(i),"available")){
+ System.out.println(booksFileHandle.getIdFromFileBook().get(i)+
+ ", "+booksFileHandle.getTitlesFromFileBook().get(i)+" exst : " + booksFileHandle.getExistsFromFileBook().get(i));
+ }
+ }
+ }
+ }catch (Exception e){
+ System.out.println("Missing args, Try command in correct way. ");
+ }
+ }
+
+ else{
+ System.out.println("Wrong format :-|");
+ }
+
+ }
+ else{
+ System.out.println("Wrong format, try again .");
+ }
+ }
+
+
+ }
+
+ public void adminUserPanel(User u){
+ String p1, p2, u1, u2;
+ System.out.println("Welcome " + u.getUser_name());
+ System.out.println("This is your admin panel.");
+ ArrayList list = new ArrayList<>();
+ String cmd;
+ v = new Verifications();
+ Scanner scn = new Scanner(System.in);
+ String date;
+ int flag;
+ String userID, userName, userPhone;
+ String book_t;
+ String query;
+ String type;
+ while (true){
+ System.out.println("Enter command (With Space ,Just one space, Please avoid to enter extra characters)");
+ System.out.println("Enter help to see help menu. ");
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(Objects.equals(cmd, "help") || Objects.equals(cmd, "Help")){
+ show_helpMenuAdmins();
+ }
+ else if((cmd.contains("lib") || cmd.contains("user")) && (!cmd.contains(" ") || !cmd.contains("*"))){
+ list = v.get_SectionsPanelQuery(cmd);
+ if(Objects.equals(list.get(1), "show") || Objects.equals(list.get(1), "Show")){
+ try {
+ if(Objects.equals(list.get(2), "books")){
+ try {
+ type = list.get(3);
+ booksFileHandle.show_booksFile(type);
+ }
+ catch (Exception e){
+ System.out.println("Missing Argument,");
+ }
+ }
+ else if(Objects.equals(list.get(2), "users")){
+ for(String line : usersFileHandle.lines_of_file()){
+ System.out.println(line);
+ }
+ }
+ else if(Objects.equals(list.get(2), "rents")){
+ for(String line : rentalFileHandle.lines_of_file()){
+ System.out.println(line);
+ }
+ }
+ else{
+ System.out.println("Try command in correct way.");
+ }
+ } catch (Exception e){
+ System.out.println("Missing args. :-|");
+ }
+ }
+ else if(Objects.equals(list.get(1), "promote") || Objects.equals(list.get(1), "Promote")){
+ try {
+ userID = list.get(2);
+ userName = list.get(3);
+ userPhone = list.get(4);
+ flag = usersFileHandle.getIDInFile().indexOf(userID);
+ // user : id,username,phonenumber,role,password
+ query = userID + "," + userName + "," + userPhone + ",admin," + usersFileHandle.getUserPassword().get(flag);
+ if(adminsFileHandle.lines_of_file().contains(query)){
+ System.out.println("You promote this user before. ");
+ }
+ else{
+ adminsFileHandle.add_to_file(query);
+ usersFileHandle.editLineInFile(usersFileHandle.lines_of_file().get(flag), "");
+ System.out.println("Done!");
+ }
+
+ }
+ catch (Exception e){
+ System.out.println("Try command in correct way.[Missing Argument or ID/Username not in repository]");
+ }
+ }
+ else if(Objects.equals(list.get(1), "remove") || Objects.equals(list.get(1), "Remove")){ // remove whole with no change
+ try {
+ if(Objects.equals(list.get(2), "user")){
+ try {
+ // to remove user : lib remove user user_id user_name user_phone
+ userID = list.get(3);
+ flag = usersFileHandle.getIDInFile().indexOf(userID);
+ if(flag == -1){
+ System.out.println("This user_id is not in user repository.");
+ }
+ else{
+ usersFileHandle.editLineInFile(usersFileHandle.lines_of_file().get(flag), "");
+ rentalFileHandle.removeRents(userID);
+ }
+ }catch (Exception e){
+ System.out.println("Missing args. :-|");
+ }
+ }
+ else if(Objects.equals(list.get(2), "book")){
+ try {
+ book_t = list.get(3);
+ flag = booksFileHandle.getTitlesFromFileBook().indexOf(book_t);
+ if(flag != -1){
+ booksFileHandle.editLineInFile(booksFileHandle.lines_of_file().get(flag), "");
+ }
+ else{
+ System.out.println("There is no book such this book in books repository");
+ }
+ }catch (Exception e){
+ System.out.println("Missing args. :-|");
+ }
+ }
+ else if(Objects.equals(list.get(2), "rent")){
+ try{
+ date = list.get(3);
+ userID = list.get(4);
+ book_t = list.get(5);
+ if(!v.dateValidation(date) || !v.userIdValidator(userID)){
+ System.out.println("Wrong date/id format try again.");
+ }
+ else{
+ query = date + "," + userID + "," + book_t;
+ if(rentalFileHandle.removeRentByQuery(query)){
+ System.out.println("Done ! :-)");
+ }
+ else{
+ System.out.println("There is no rent like that.");
+ }
+ }
+ //query = date + "," + userID + "," + book_t;
+
+ }catch (Exception e){
+ System.out.println("Missing args. :-|");
+ }
+ }
+ else{
+ System.out.println("Missing arguments. ");
+ }
+ }
+ catch (Exception e){
+ System.out.println("Missing Args, Try command in correct way.");
+ }
+ }
+ else if(Objects.equals(list.get(1), "edit") || Objects.equals(list.get(1), "Edit")){
+ // edit your info
+ if(Objects.equals(list.get(2), "ph")){
+ try {
+ // edit phonenumber
+ p1 = list.get(3);
+ p2 = list.get(4);
+ while(true){
+ if(v.userPhonenumberValidator(p2)){
+ break;
+ }
+ else{
+ System.out.println("Enter valid username .");
+ System.out.println("User phonenumber must start with any number instead of 0 with length 10");
+ p2 = scn.nextLine();
+ }
+ }
+ if(adminsFileHandle.getPhoneNumbersInFile().contains(p1)){
+ while (true){
+ if(!adminsFileHandle.getPhoneNumbersInFile().contains(p2))
+ break;
+ else{
+ System.out.println("This phonenumber is already taken . try another one");
+ System.out.print(">>>");
+ p2 = scn.nextLine();
+ }
+ }
+
+ int i = adminsFileHandle.getPhoneNumbersInFile().indexOf(p1);
+ if(Objects.equals(p1, u.getPhonenumber())){
+ query = adminsFileHandle.getIDInFile().get(i)+","+
+ adminsFileHandle.getUsernameInFile().get(i)+","+p2+",normal,"+adminsFileHandle.getUserPassword().get(i);
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(i), query);
+ System.out.println("phonenumber has been updated");
+ }
+ else{
+ System.out.println("Repeat your command, your current username is not correct in input. ");
+ }
+
+ }
+ else{
+ System.out.println("There is no phone number like that in users repository");
+ }
+ }
+ catch (Exception e){
+ System.out.println("Missing Arguments.");
+ }
+ }
+ else if(Objects.equals(list.get(2), "usr")){
+ try{
+ u1 = list.get(3);
+ u2 = list.get(4);
+ while(true){
+ if(v.userUsernameValidator(u2)){
+ break;
+ }
+ else{
+ System.out.println("Enter valid username .");
+ System.out.println("Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ u2 = scn.nextLine();
+ }
+ }
+ if(adminsFileHandle.getUsernameInFile().contains(u1)){
+ while (true){
+ if(!adminsFileHandle.getUsernameInFile().contains(u2))
+ break;
+ else{
+ System.out.println("This username is already taken . try another one");
+ System.out.print(">>>");
+ u2 = scn.nextLine();
+ }
+ }
+ int i = adminsFileHandle.getUsernameInFile().indexOf(u1);
+ if(Objects.equals(u1, u.getUser_name())){
+ query = adminsFileHandle.getIDInFile().get(i)+","+
+ u2+","+adminsFileHandle.getPhoneNumbersInFile().get(i)+",normal,"+adminsFileHandle.getUserPassword().get(i);
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(i), query);
+ u.set_new_username(u2);
+ System.out.println("Your username has been updated");
+ }
+ else{
+ System.out.println("Repeat your command, your current username is not correct in input. ");
+ }
+
+ }
+ else{
+ System.out.println("This username is not in users repository");
+ }
+ }
+ catch (Exception e){
+ System.out.println("Missing Arguments,");
+ }
+ }
+ else if(Objects.equals(list.get(2), "pss")){
+ try{
+ p1 = list.get(3);
+ p2 = list.get(4);
+ while (true){
+ if(v.userPasswordValidator(p2)){
+ break;
+ }
+ else{
+ System.out.println("Wrong format, try another password.");
+ }
+ }
+
+ if(!Objects.equals(p1, u.getPassword())){
+ System.out.println("Try command again, current password is not correct.");
+ }
+ else{
+ int i = adminsFileHandle.getUserPassword().indexOf(p1);
+ query = adminsFileHandle.getIDInFile().get(i)+"," + adminsFileHandle.getUsernameInFile().get(i)+","+
+ adminsFileHandle.getPhoneNumbersInFile().get(i) + ",normal,"+p2;
+ adminsFileHandle.editLineInFile(adminsFileHandle.lines_of_file().get(i), query);
+ System.out.println("Your password has been updated.");
+ }
+
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ System.out.println("Missing Arguments. ");
+ }
+ }
+ else if(Objects.equals(list.get(2), "admin")){
+ adminEditPanel(u);
+ }
+ else{
+ System.out.println("Try command in correct way. ");
+ }
+
+ }
+ else if(Objects.equals(list.get(1), "add") || Objects.equals(list.get(1),"Add")){
+ // add book
+ String title, auth, desc;
+ title = list.get(2);
+ auth = list.get(3);
+ desc = list.get(4);
+ if(booksFileHandle.getAuthorsFromFileBook().contains(auth) && booksFileHandle.getTitlesFromFileBook().contains(title) &&
+ booksFileHandle.getDescriptionsFromFileBook().contains(desc)){
+ // inc existence
+ System.out.println("This book is added before.");
+ int i = booksFileHandle.getAuthorsFromFileBook().indexOf(auth);
+ String new_exst = String.valueOf(Integer.valueOf(booksFileHandle.getExistsFromFileBook().get(i))+1);
+ query = booksFileHandle.getIdFromFileBook().get(i) + "," +booksFileHandle.getTitlesFromFileBook().get(i)+","+
+ booksFileHandle.getAuthorsFromFileBook().get(i)+","+booksFileHandle.getDescriptionsFromFileBook().get(i)+","+
+ "available,"+new_exst;
+ booksFileHandle.editLineInFile(booksFileHandle.lines_of_file().get(i), query);
+ }
+ else{
+ // add a new book
+ String id = String.valueOf(booksFileHandle.set_id()+1);
+ String existence = "1";
+ query = id+","+title+","+auth+","+desc+","+"available,"+existence;
+ booksFileHandle.add_to_file(query);
+ System.out.println("Book is added successfully.");
+ }
+ }
+ else{
+ System.out.println("Try command in a correct way.");
+ }
+ }
+ else if(Objects.equals(cmd, "exit")){
+ break;
+ }
+ else{
+ System.out.println("wrong command. try again :-|");
+ }
+ }
+
+ }
+
+
+}
+
+/*
+System.out.println("Enter your id :");
+ id = scn.nextLine();
+ if(usersFileHandle.getIDInFile().contains(id)){
+ System.out.println("You have been registered before. Login please:-)");
+ }
+ else {
+ while(true){
+ if(v.userIdValidator(id)){
+ break;
+ }
+ else{
+ System.out.println("Enter id again, your ID must be numerical with length between 10 and 15");
+ id = scn.nextLine();
+ }
+ }
+ System.out.println("Enter your username :");
+ System.out.println("Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ while(true){
+ username = scn.nextLine();
+ if(!v.userUsernameValidator(username) || usersFileHandle.getUsernameInFile().contains(username)){
+ System.out.println("Wrong Input try again :-|");
+ }
+ else{
+ break;
+ }
+ }
+ System.out.println("Enter your phonenumber :");
+ System.out.println("User phonenumber must start with any number instead of 0 with length 10");
+ while(true){
+ phonenumber = scn.nextLine();
+ if(!v.userPhonenumberValidator(phonenumber) || usersFileHandle.getPhoneNumbersInFile().contains(phonenumber)){
+ System.out.println("Wrong Input try again :-|");
+ }
+ else{
+ break;
+ }
+ }
+
+ }
+ */
+
+
+/*
+while (true){
+ id = scn.nextLine();
+ if(v.userIdValidator(id))
+ break;
+ else{
+ System.out.println("Wrong format, try again.");
+ }
+ }
+ System.out.println("Enter username :");
+ System.out.println("Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ while (true){
+ username = scn.nextLine();
+ if(v.userUsernameValidator(username)){
+ break;
+ }
+ else{
+ System.out.println("Wrong format, try again.");
+ }
+ }
+ System.out.println("Enter a phonenumber :");
+ System.out.println("User phonenumber must start with any number instead of 0 with length 10");
+ while (true){
+ phonenumber = scn1.nextLine();
+ if(v.userPhonenumberValidator(phonenumber)){
+ break;
+ }
+ else{
+ System.out.println("Wrong Format, Try again.");
+ }
+ }
+ // now to check file
+ if(usersFileHandle.getUsernameInFile().contains(username) || usersFileHandle.getIDInFile().contains(id)
+ || usersFileHandle.getPhoneNumbersInFile().contains(phonenumber)){
+ System.out.println("Sorry, We found your id/username/phonenumber , Please goto login panel");
+ return;
+ }
+ System.out.println("Set a password for yourself :");
+ System.out.println("Password must include 0->9 and a->z and A->Z , just underline '_' not dash '-'");
+ while (true){
+ pass = scn.nextLine();
+ if(v.userPasswordValidator(pass)){
+ break;
+ }
+ else{
+ System.out.println("Wrong Format, Try Again.");
+ }
+ }
+ u = new User(username, id, phonenumber,"normal", pass);
+ usersFileHandle.addUser(u);
+ */
+
+/*
+if(i != -1){
+ if(rentalFileHandle.getRentalsUserID().contains(user_ID)){
+ f = rentalFileHandle.getRentalsUserID().indexOf(user_ID);
+ if(!Objects.equals(rentalFileHandle.getRentalsBookID().get(f), id)){
+ if(Objects.equals(booksFileHandle.getStatsFromFileBook().get(i), "in-rent")){
+ System.out.println("this book "+id+" is actually in rent try another books.");
+ System.out.println("To show available books try show books command.");
+ }
+ else{
+ if(usersFileHandle.getIDInFile().contains(user_ID)){
+ query = date + "," + user_ID + "," + booksFileHandle.getIdFromFileBook().get(i);
+ booksFileHandle.change_status_inFileRent(booksFileHandle.getIdFromFileBook().get(i));
+ rentalFileHandle.add_to_file(query);
+ }
+ else{
+ System.out.println("Wrong ID, there is no id in repository like that. :-|");
+ }
+ }
+ }
+ else{
+ System.out.println("there is rent just like the rent, try another book.");
+ }
+ }
+ else{
+
+ }
+ }
+ else{
+ System.out.println("This book with this id is not available in book repository. :-|");
+ System.out.println("Try command with appropriate query. :-)");
+ }
+ */
+
+/*
+if(true){
+ flag = rentalFileHandle.getRentalsUserID().indexOf(user_id);
+ String new_query = "";
+ String line = rentalFileHandle.lines_of_file().get(flag);
+ rentalFileHandle.editLineInFile(line, new_query);
+ booksFileHandle.change_status_inFileReturnCase(bookId);
+
+ }else{
+ System.out.println("No such rental details are available. :-|");
+ }
+ */
\ No newline at end of file
diff --git a/Answers/40230112081/MyApp.java b/Answers/40230112081/MyApp.java
new file mode 100644
index 0000000..a521ee3
--- /dev/null
+++ b/Answers/40230112081/MyApp.java
@@ -0,0 +1,62 @@
+import java.io.IOException;
+import java.util.Objects;
+import java.util.Scanner;
+
+public class MyApp {
+ public static void main(String[] args) throws IOException, InterruptedException {
+ Library lib = new Library("Nit central library", "7a.m.-7p.m.",100);
+ Scanner scn = new Scanner(System.in);
+ String cmd;
+ if(!lib.isLibOpen()){
+ while (true){
+ System.out.print("\033[H\033[2J");
+ System.out.println("***************************************************");
+ System.out.println("Welcome to "+ lib.getLibName());
+ System.out.println("Each commands start with lib : Instructions below.");
+ System.out.println("to login : lib login");
+ System.out.println("to sign up as normal user : lib signup");
+ System.out.println("to exit : just enter exit");
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(cmd.contains("lib")){
+ if(Objects.equals(cmd, "lib signup")){
+ System.out.print("\033[H\033[2J");
+ lib.add_normalUser();
+ }
+ else if (Objects.equals(cmd, "lib login")) {
+ System.out.print("\033[H\033[2J");
+ System.out.println("Login as Admin / Normal user (type admin or normal or exit to return to main menu):");
+ while (true){
+ System.out.print(">>>");
+ cmd = scn.nextLine();
+ if(Objects.equals(cmd, "exit")){
+ break;
+ }
+ else if(Objects.equals(cmd, "admin") || Objects.equals(cmd,"normal"))
+ break;
+ else{
+ System.out.println("Wrong input :-|");
+ }
+
+ }
+ if(Objects.equals(cmd, "admin") || Objects.equals(cmd,"Admin")){
+ lib.login_AdminUsers();
+ }
+ else if(Objects.equals(cmd, "normal") || Objects.equals(cmd, "Normal")){
+ lib.login_normalUsers();
+ }
+ }
+ }
+ else if(Objects.equals(cmd, "exit")){
+ break;
+ }
+ else{
+ System.out.println("Wrong format: try again");
+ }
+ }
+ }
+ else{
+ System.out.println("Thanks for choosing "+lib.getLibName()+", Library is closed");
+ }
+ }
+}
diff --git a/Answers/40230112081/Rent.java b/Answers/40230112081/Rent.java
new file mode 100644
index 0000000..5875326
--- /dev/null
+++ b/Answers/40230112081/Rent.java
@@ -0,0 +1,28 @@
+public class Rent {
+ private Book rentalBook;
+ private User userToRentBook;
+ private String date;
+
+ // constructor
+ public Rent(Book book, User nrmUser, String date){
+ this.rentalBook = book;
+ this.userToRentBook = nrmUser;
+ this.date = date;
+ }
+
+ // getters
+
+ public String getDate(){
+ return this.date;
+ }
+
+ public String getUserID(){
+ return this.userToRentBook.getUserID();
+ }
+
+ public String getBookID(){
+ return this.rentalBook.getId();
+ }
+
+
+}
diff --git a/Answers/40230112081/Rental.txt b/Answers/40230112081/Rental.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Answers/40230112081/User.java b/Answers/40230112081/User.java
new file mode 100644
index 0000000..7c6ea96
--- /dev/null
+++ b/Answers/40230112081/User.java
@@ -0,0 +1,28 @@
+public class User {
+ private String user_name;
+ private String userID;
+ private String phonenumber;
+ private String role;
+ private String password;
+
+ // constructor
+ public User(String userName, String userId, String phoneNumber, String role, String _pass)
+ {
+ this.role = role;
+ this.phonenumber = phoneNumber;
+ this.user_name = userName;
+ this.userID = userId;
+ this.password = _pass;
+ }
+
+ // getters
+ public String getUserID() { return this.userID; }
+ public String getUser_name() { return this.user_name; }
+ public String getPhonenumber() { return this.phonenumber; }
+ public String getRole() { return this.role; }
+ public String getPassword() { return this.password; }
+
+ public void set_new_username(String new_user){
+ this.user_name = new_user;
+ }
+}
diff --git a/Answers/40230112081/Users.txt b/Answers/40230112081/Users.txt
new file mode 100644
index 0000000..0f6bf68
--- /dev/null
+++ b/Answers/40230112081/Users.txt
@@ -0,0 +1 @@
+4990214560,Amir,9114434321,normal,Amir_1123
diff --git a/Answers/40230112081/Verifications.java b/Answers/40230112081/Verifications.java
new file mode 100644
index 0000000..aa6b9ad
--- /dev/null
+++ b/Answers/40230112081/Verifications.java
@@ -0,0 +1,110 @@
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class Verifications {
+
+ public int ascii(char ch){
+ return (int)ch;
+ }
+ public boolean userIdValidator(String _id_){
+ // User ID must be numerical with length between 10 and 15
+ // ASCII Approach
+ if(_id_.length() < 10 || _id_.length() > 15)
+ return false;
+ else{
+ for(char ch : _id_.toCharArray()){
+ if(ascii(ch) < 48 || ascii(ch) > 57)
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean userUsernameValidator(String _username_){
+ // Username must include 0->9 and a->z and A->Z , just underline '_' not dash '-'
+ ArrayList valid_chars = new ArrayList<>();
+ String upperAlph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ String Alph = upperAlph.toLowerCase();
+ String numbers = "0123456789";
+
+ for(Character ch : upperAlph.toCharArray()){
+ valid_chars.add(ch);
+ }
+ for(Character ch : Alph.toCharArray()){
+ valid_chars.add(ch);
+ }
+ for(Character ch : numbers.toCharArray()){
+ valid_chars.add(ch);
+ }
+ valid_chars.add('_');
+ for(Character ch : _username_.toCharArray()){
+ if(!valid_chars.contains(ch))
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean userPasswordValidator(String _password_){
+ // Password must include 0->9 and a->z and A->Z , just underline '_' not dash '-'
+ ArrayList valid_chars = new ArrayList<>();
+ String upperAlph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ String Alph = upperAlph.toLowerCase();
+ String numbers = "0123456789";
+
+ for(Character ch : upperAlph.toCharArray()){
+ valid_chars.add(ch);
+ }
+ for(Character ch : Alph.toCharArray()){
+ valid_chars.add(ch);
+ }
+ for(Character ch : numbers.toCharArray()){
+ valid_chars.add(ch);
+ }
+ valid_chars.add('_');
+ for(Character ch : _password_.toCharArray()){
+ if(!valid_chars.contains(ch))
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean userPhonenumberValidator(String _phonenumber_){
+ // User phonenumber must start with any number instead of 0
+ // length must be 10
+ // ASCII approach
+ if(_phonenumber_.length() < 10 || _phonenumber_.length() > 10)
+ return false;
+ else
+ {
+ for(char ch : _phonenumber_.toCharArray()){
+ if(ascii(ch) < 48 || ascii(ch) > 57)
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public ArrayList get_SectionsPanelQuery(String query){
+ ArrayList str = new ArrayList<>();
+ for(String word : query.split(" +")){
+ str.add(word);
+ }
+ return str;
+ }
+
+ public boolean dateValidation(String date){
+ if(!date.contains("/")){
+ return false;
+ }
+ int f1, f2;
+ f1 = date.indexOf("/", 0);
+ f2 = date.indexOf("/", f1+1);
+ if(date.substring(f1+1,f2).matches("[0-9]")){
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/Answers/40230112081/myFileCLass.java b/Answers/40230112081/myFileCLass.java
new file mode 100644
index 0000000..ae59134
--- /dev/null
+++ b/Answers/40230112081/myFileCLass.java
@@ -0,0 +1,490 @@
+import java.io.*;
+import java.lang.reflect.Array;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Objects;
+import java.util.Scanner;
+public class myFileCLass {
+ public File f;
+ public String dir;
+ public void add_to_file(String query){
+ f = new File(dir);
+ FileOutputStream fos = null;
+ try
+ {
+ fos = new FileOutputStream(f, true);
+ fos.write(query.getBytes(StandardCharsets.UTF_8));
+ fos.write("\n".getBytes(StandardCharsets.UTF_8));
+ }catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally {
+ try{
+ if(fos != null)
+ fos.close();
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public ArrayList lines_of_file()
+ {
+ f = new File(dir);
+ String line;
+ ArrayList lines = new ArrayList<>();
+ BufferedReader br = null;
+ FileReader fr = null;
+ try{
+ fr = new FileReader(f);
+ br = new BufferedReader(fr); // use buffer reader to read more efficient
+ while((line = br.readLine()) != null){
+ lines.add(line);
+ }
+
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ try {
+ if(fr != null)
+ fr.close();
+ if(br != null)
+ br.close();
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ return lines;
+ }
+
+ public void show_myUsername(){
+ System.out.println("Enter your phonenumber :");
+ String phone;
+ Scanner scn = new Scanner(System.in);
+ phone = scn.nextLine();
+ int i = getPhoneNumbersInFile().indexOf(phone);
+ if(i != -1) {
+ System.out.println(getUsernameInFile().get(i));
+ return;
+ }
+ else{
+ System.out.println("Your phonenumber is not found, try phonenumber you were signed up");
+ }
+
+ }
+ public void show_myPassword(){
+ System.out.println("Enter your phonenumber :");
+ String phone;
+ Scanner scn = new Scanner(System.in);
+ phone = scn.nextLine();
+ int i = getPhoneNumbersInFile().indexOf(phone);
+ if(i != -1) {
+ System.out.println(getUserPassword().get(i));
+ return;
+ }
+ else{
+ System.out.println("Your phonenumber is not found, try phonenumber you were signed up");
+ }
+ }
+ public void editLineInFile(String lineToEdit, String newLine) {
+ try {
+ // Read the file
+ f = new File(dir);
+ BufferedReader reader = new BufferedReader(new FileReader(f));
+ String line;
+ StringBuilder fileContent = new StringBuilder();
+ //ArrayList file_content = new ArrayList<>();
+ // Read each line and replace if it matches
+ while ((line = reader.readLine()) != null) {
+ if (line.equals(lineToEdit)) {
+ fileContent.append(newLine).append("\n");
+ } else if(!line.equals(lineToEdit)){
+ fileContent.append(line).append("\n");
+ }
+ }
+ reader.close();
+
+ // Write back to the file
+ FileWriter writer = new FileWriter(dir);
+ writer.write(fileContent.toString());
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ deleteEmptyLine();
+
+ }
+ public int set_id(){
+ return lines_of_file().size();
+ }
+
+ public void addUser(User u){
+ String username = u.getUser_name();
+ String id = u.getUserID();
+ String phone = u.getPhonenumber();
+ String role = u.getRole();
+ String pass = u.getPassword();
+ String query =id+","+username + "," +phone+","+role+","+pass;
+ add_to_file(query);
+ }
+
+ public ArrayList getIDInFile(){
+ int flag;
+ ArrayList ids = new ArrayList<>();
+ ArrayList lines = lines_of_file();
+ for(String l : lines){
+ if(Objects.equals(l, ""))
+ continue;
+ flag = l.indexOf(",");
+ ids.add(l.substring(0, flag));
+ }
+ return ids;
+ }
+ public ArrayList getUsernameInFile(){
+ int f1, f2;
+ ArrayList usernames = new ArrayList<>();
+ ArrayList lines = lines_of_file();
+ for(String l : lines){
+ if(Objects.equals(l, ""))
+ continue;
+ f1 = l.indexOf(",");
+ f2 = l.indexOf(",", f1+1);
+ usernames.add(l.substring(f1+1,f2));
+ }
+ return usernames;
+ }
+ public ArrayList getPhoneNumbersInFile(){
+ int f1,f2,f3;
+ ArrayList phones = new ArrayList<>();
+ ArrayList lines = lines_of_file();
+ for(String l : lines){
+ if(Objects.equals(l, ""))
+ continue;
+ f1 = l.indexOf(",");
+ f2 = l.indexOf(",", f1+1);
+ f3 = l.indexOf(",",f2+1);
+ phones.add(l.substring(f2+1, f3));
+ }
+ return phones;
+ }
+ public ArrayList getUserRolesInFile(){
+ int f1,f2,f3,f4;
+ ArrayList roles = new ArrayList<>();
+ ArrayList lines = lines_of_file();
+ for(String l : lines){
+ if(Objects.equals(l, ""))
+ continue;
+ f1 = l.indexOf(",");
+ f2 = l.indexOf(",", f1+1);
+ f3 = l.indexOf(",",f2+1);
+ f4 = l.indexOf(",", f3+1);
+ roles.add(l.substring(f3+1,f4));
+ }
+ return roles;
+ }
+
+ public ArrayList getUserPassword(){
+ int f1,f2,f3,f4;
+ ArrayList passwords = new ArrayList<>();
+ ArrayList lines = lines_of_file();
+ for(String l : lines){
+ if(Objects.equals(l, ""))
+ continue;
+ f1 = l.indexOf(",");
+ f2 = l.indexOf(",", f1+1);
+ f3 = l.indexOf(",",f2+1);
+ f4 = l.indexOf(",", f3+1);
+ passwords.add(l.substring(f4+1));
+ }
+ return passwords;
+ }
+
+ public void addBook(Book b){
+ String query;
+ String id, title, author, desc, status;
+ id = b.getId();
+ title = b.getTitle();
+ author = b.getAuthor();
+ desc = b.getDescription();
+ status = b.getStatus();
+ int exst = b.getExistence();
+ query = id + "," + title + "," + author + "," + desc + "," + status + "," + String.valueOf(exst);
+ add_to_file(query);
+ }
+
+ public ArrayList getIdFromFileBook(){
+ int f1;
+ ArrayList lines = lines_of_file();
+ ArrayList ids = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ ids.add(str.substring(0, f1));
+ }
+ return ids;
+ }
+
+ public ArrayList getTitlesFromFileBook(){
+ int f1,f2;
+ ArrayList lines = lines_of_file();
+ ArrayList titles = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ f2 = str.indexOf(",", f1+1);
+ titles.add(str.substring(f1+1, f2));
+ }
+ return titles;
+ }
+ public ArrayList getAuthorsFromFileBook(){
+ int f1,f2, f3;
+ ArrayList lines = lines_of_file();
+ ArrayList authors = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ f2 = str.indexOf(",", f1+1);
+ f3 = str.indexOf(",", f2+1);
+ authors.add(str.substring(f2+1, f3));}
+ return authors;
+ }
+ public ArrayList getDescriptionsFromFileBook(){
+ int f1,f2, f3, f4;
+ ArrayList lines = lines_of_file();
+ ArrayList descrips = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ f2 = str.indexOf(",", f1+1);
+ f3 = str.indexOf(",", f2+1);
+ f4 = str.indexOf(",", f3+1);
+ descrips.add(str.substring(f3+1, f4));
+ }
+ return descrips;
+ }
+ public ArrayList getStatsFromFileBook(){
+ int f1,f2, f3, f4, f5;
+ ArrayList lines = lines_of_file();
+ ArrayList stats = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ f2 = str.indexOf(",", f1+1);
+ f3 = str.indexOf(",", f2+1);
+ f4 = str.indexOf(",", f3+1);
+ f5 = str.indexOf(",", f4+1);
+ stats.add(str.substring(f4+1,f5));
+ }
+ return stats;
+ }
+
+ public ArrayList getExistsFromFileBook(){
+ int f1,f2, f3, f4, f5;
+ ArrayList lines = lines_of_file();
+ ArrayList exists = new ArrayList<>();
+ for(String str : lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",");
+ f2 = str.indexOf(",", f1+1);
+ f3 = str.indexOf(",", f2+1);
+ f4 = str.indexOf(",", f3+1);
+ f5 = str.indexOf(",", f4+1);
+ exists.add(str.substring(f5+1));
+ }
+ return exists;
+ }
+
+
+ public void addRental(Rent r){
+ String query;
+ String date = r.getDate();
+ String userID = r.getUserID();
+ String bookID = r.getBookID();
+
+ query = date+","+userID+","+bookID;
+ add_to_file(query);
+ }
+
+ public ArrayList getRentalsDate(){
+ ArrayList lines = lines_of_file();
+ ArrayList dates = new ArrayList<>();
+ int f1;
+ for(String str: lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",", 0);
+ dates.add(str.substring(0, f1));
+ }
+ return dates;
+ }
+
+ public ArrayList getRentalsUserID(){
+ ArrayList lines = lines_of_file();
+ ArrayList userIds = new ArrayList<>();
+ int f1, f2;
+ for(String str: lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",", 0);
+ f2 = str.indexOf(",", f1+1);
+ userIds.add(str.substring(f1+1, f2));
+ }
+ return userIds;
+ }
+
+ public ArrayList getRentalsBookID(){
+ ArrayList lines = lines_of_file();
+ ArrayList bookIds = new ArrayList<>();
+ int f1, f2;
+ for(String str: lines){
+ if(Objects.equals(str, ""))
+ continue;
+ f1 = str.indexOf(",", 0);
+ f2 = str.indexOf(",", f1+1);
+ bookIds.add(str.substring(f2+1));
+ }
+ return bookIds;
+ }
+
+ public void change_status_inFileRent(String book_id){ // just for book & reduce existence for rent
+ int f = getIdFromFileBook().indexOf(book_id);
+ String new_query;
+ int currentExistence = Integer.valueOf(getExistsFromFileBook().get(f));
+ if(currentExistence > 1){
+ currentExistence--;
+ new_query = book_id + "," + getTitlesFromFileBook().get(f) + "," + getAuthorsFromFileBook().get(f)+
+ "," + getDescriptionsFromFileBook().get(f) + "," + "available," + String.valueOf(currentExistence);
+ editLineInFile(lines_of_file().get(f), new_query);
+ }
+ else {
+ currentExistence--;
+ new_query = book_id+ "," + getTitlesFromFileBook().get(f) + "," + getAuthorsFromFileBook().get(f)+
+ "," + getDescriptionsFromFileBook().get(f) + "," + "in-rent," + String.valueOf(currentExistence);
+ editLineInFile(lines_of_file().get(f), new_query);
+ }
+ }
+
+ public void change_status_inFileReturnCase(String book_id){
+ int f = getIdFromFileBook().indexOf(book_id);
+ String new_query;
+ int currentExistence = Integer.valueOf(getExistsFromFileBook().get(f));
+ if(currentExistence > 0){
+ currentExistence++;
+ new_query = book_id + "," + getTitlesFromFileBook().get(f) + "," + getAuthorsFromFileBook().get(f)+
+ "," + getDescriptionsFromFileBook().get(f) + "," + "available," + String.valueOf(currentExistence);
+ editLineInFile(lines_of_file().get(f), new_query);
+ }
+ else if(currentExistence == 0){
+ currentExistence++;
+ new_query = book_id+","+ getTitlesFromFileBook().get(f) + "," + getAuthorsFromFileBook().get(f)+
+ "," + getDescriptionsFromFileBook().get(f) + "," + "available," + String.valueOf(currentExistence);
+ editLineInFile(lines_of_file().get(f), new_query);
+ }
+ }
+
+ public void show_booksFile(String type){
+ int flag;
+ if(Objects.equals(type, "-A")){
+ for(String line : lines_of_file()){
+ System.out.println(line);
+ }
+ }
+ else if(Objects.equals(type, "-E")){ // existed books
+ for(int i = 0;i < getStatsFromFileBook().size();i++){
+ if(Objects.equals(getStatsFromFileBook().get(i), "available")){
+ System.out.println(lines_of_file().get(i));
+ }
+ }
+ }
+ else if(Objects.equals(type, "-R")){ // existed books
+ for(int i = 0;i < getStatsFromFileBook().size();i++){
+ if(Objects.equals(getStatsFromFileBook().get(i), "in-rent")){
+ System.out.println(lines_of_file().get(i));
+ }
+ }
+ }
+ else{
+ System.out.println("Nothing to show. :-| ");
+ }
+
+ }
+
+ public String getDate_fromSingleLine(String line){ // rentals
+ String date;
+ int f1 = line.indexOf(",");
+ date = line.substring(0, f1);
+ return date;
+ }
+
+ public void deleteEmptyLine(){
+ File temp;
+ String line;
+ try {
+ f = new File(dir);
+ temp = new File("temp.txt");
+
+ BufferedReader reader = new BufferedReader(new FileReader(f));
+ BufferedWriter writer = new BufferedWriter(new FileWriter(temp));
+ while((line = reader.readLine()) != null){
+ if(!line.trim().isEmpty()){
+ writer.write(line);
+ writer.newLine();
+ }
+ }
+ reader.close();
+ writer.close();
+
+ if(!f.delete()){
+ System.out.println("Could not to delete");
+ return;
+ }
+ if(temp.renameTo(f)){
+ //System.out.println("Could not to rename");
+ return;
+ }
+
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void removeRents(String userID){ // remove all rents with this userID in case of remove user for admin
+ for(String line : lines_of_file()){
+ if(line.contains(userID)){
+ editLineInFile(line, "");
+ }
+ }
+ }
+
+ public boolean removeRentByQuery(String query){ // remove rent by query = date+userID+bookID
+ for(String line : lines_of_file()){
+ if(Objects.equals(line, query)){
+ editLineInFile(line, "");
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
+
+
+// user : id,username,phonenumber,role,password
+// book : id,title,author,description,status,existence
+// rent : date,userID,bookID
+
+/*
+int f = booksFileHandle.getStatsFromFileBook().indexOf(status);
+ */
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/.idea/.gitignore b/Answers/40230112081/out/production/40230112081/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Answers/40230112081/out/production/40230112081/.idea/40230112081.iml b/Answers/40230112081/out/production/40230112081/.idea/40230112081.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/40230112081.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/.idea/misc.xml b/Answers/40230112081/out/production/40230112081/.idea/misc.xml
new file mode 100644
index 0000000..07115cd
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/.idea/modules.xml b/Answers/40230112081/out/production/40230112081/.idea/modules.xml
new file mode 100644
index 0000000..4567373
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/.idea/uiDesigner.xml b/Answers/40230112081/out/production/40230112081/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/.idea/vcs.xml b/Answers/40230112081/out/production/40230112081/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/40230112081/out/production/40230112081/Admins.txt b/Answers/40230112081/out/production/40230112081/Admins.txt
new file mode 100644
index 0000000..25610e6
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/Admins.txt
@@ -0,0 +1,3 @@
+40230112081,Masoud,9121231234,admin,Masoud
+40230112081,Amir1,9120719012,admin,1234
+1234512345,krm,9112342345,admin,1234
diff --git a/Answers/40230112081/out/production/40230112081/Book.class b/Answers/40230112081/out/production/40230112081/Book.class
new file mode 100644
index 0000000..ec3052e
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/Book.class differ
diff --git a/Answers/40230112081/out/production/40230112081/Books.txt b/Answers/40230112081/out/production/40230112081/Books.txt
new file mode 100644
index 0000000..516bdd1
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/Books.txt
@@ -0,0 +1,2 @@
+1,Math,Salehi,Calc,available,1
+3,Book1,Author1,Desc1,available,1
diff --git a/Answers/40230112081/out/production/40230112081/Library.class b/Answers/40230112081/out/production/40230112081/Library.class
new file mode 100644
index 0000000..2914017
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/Library.class differ
diff --git a/Answers/40230112081/out/production/40230112081/MyApp.class b/Answers/40230112081/out/production/40230112081/MyApp.class
new file mode 100644
index 0000000..9515a3a
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/MyApp.class differ
diff --git a/Answers/40230112081/out/production/40230112081/Rent.class b/Answers/40230112081/out/production/40230112081/Rent.class
new file mode 100644
index 0000000..4dd3fc4
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/Rent.class differ
diff --git a/Answers/40230112081/out/production/40230112081/Rental.txt b/Answers/40230112081/out/production/40230112081/Rental.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Answers/40230112081/out/production/40230112081/User.class b/Answers/40230112081/out/production/40230112081/User.class
new file mode 100644
index 0000000..6d819ff
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/User.class differ
diff --git a/Answers/40230112081/out/production/40230112081/Users.txt b/Answers/40230112081/out/production/40230112081/Users.txt
new file mode 100644
index 0000000..0f6bf68
--- /dev/null
+++ b/Answers/40230112081/out/production/40230112081/Users.txt
@@ -0,0 +1 @@
+4990214560,Amir,9114434321,normal,Amir_1123
diff --git a/Answers/40230112081/out/production/40230112081/Verifications.class b/Answers/40230112081/out/production/40230112081/Verifications.class
new file mode 100644
index 0000000..274a1fb
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/Verifications.class differ
diff --git a/Answers/40230112081/out/production/40230112081/myFileCLass.class b/Answers/40230112081/out/production/40230112081/myFileCLass.class
new file mode 100644
index 0000000..7b9ec2d
Binary files /dev/null and b/Answers/40230112081/out/production/40230112081/myFileCLass.class differ