diff --git a/Answers/Add Your Projects Here.txt b/Answers/Add Your Projects Here.txt deleted file mode 100644 index e69de29..0000000 diff --git a/Answers/_40230112134/.gitignore b/Answers/_40230112134/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/Answers/_40230112134/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Answers/_40230112134/.idea/.gitignore b/Answers/_40230112134/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Answers/_40230112134/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Answers/_40230112134/.idea/encodings.xml b/Answers/_40230112134/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Answers/_40230112134/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/misc.xml b/Answers/_40230112134/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/Answers/_40230112134/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/uiDesigner.xml b/Answers/_40230112134/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/Answers/_40230112134/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/.idea/vcs.xml b/Answers/_40230112134/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/Answers/_40230112134/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Answers/_40230112134/Book.txt b/Answers/_40230112134/Book.txt new file mode 100644 index 0000000..733cab3 --- /dev/null +++ b/Answers/_40230112134/Book.txt @@ -0,0 +1,12 @@ +5/f/f/f/true +6/g/g/g/true +7/hj/jkk/jk/true +8/979765/64894/56/true +49/888/88/88/true +956/asds/asdas/asds/true +104/sDA/ASDAS/add/true +288/4653/98465/8945632/true +940/lllllllllllll/lllllllllllll/lllllllllllll/true +871/;/'/'/true +66/;/;/;/true +3/d/d/d/true \ No newline at end of file diff --git a/Answers/_40230112134/NormalUser.txt b/Answers/_40230112134/NormalUser.txt new file mode 100644 index 0000000..9d11674 --- /dev/null +++ b/Answers/_40230112134/NormalUser.txt @@ -0,0 +1,2 @@ +40230112134/ad/84965/2024-05-17 +56/adfsgd/98465/2024-05-17 diff --git a/Answers/_40230112134/README.md b/Answers/_40230112134/README.md new file mode 100644 index 0000000..091d49d --- /dev/null +++ b/Answers/_40230112134/README.md @@ -0,0 +1,85 @@ +# Library Management System + +Welcome to our Library Management System (LMS) project! In this endeavor, we aim to implement a comprehensive library program with a user-friendly command-line interface (CLI). Our system caters to two distinct roles: + +1. Normal Users +2. Admins + +## Features + +- New users can seamlessly sign up using their student ID and their information. +- Our system boasts a robust admin panel, with the ability to add new admins, books, and perform book removals. +- Normal users enjoy the convenience of borrowing and returning books hassle-free. +- Each user, whether normal or admin, can conveniently delete their account whenever necessary. + +## Implementation Guidelines + +Our project is grounded in Object-Oriented Programming (OOP) principles, leveraging the following key classes: + +### Book + +Each book is characterized by the following attributes: +- Unique bookID +- Title +- Author +- Availability status +- Description + +Attributes are encapsulated within the Book class to maintain data integrity. Upon instantiation, a book's availability status is automatically status to true, and a unique bookID is generated. + +### User + +Users possess the following attributes: +- Name +- Unique ID +- Phone number + +User information is essential for system operations, and each user is uniquely identified by an ID. + +### Normal User + +In addition to the standard user attributes, normal users are also timestamped with their date of registration. + +### Admin + +Admins share user attributes but possess additional privileges and authentication through a password. + +### Rent + +The Rent class acts as a bridge between users and books, facilitating book rental transactions. Key attributes include: +- Book object +- Normal user object +- Rental ID +- Rental date + +### Library + +The central hub of our system, the Library class encapsulates core library functionalities: +- Library name +- Capacity +- Operating hours +- Book repository +- User and rental registries + +Methodologies like book rental, return, addition, and removal of members and books are seamlessly handled within the Library class. + +## Command-Line Interface (CLI) + +Our CLI class facilitates user interaction through intuitive commands: + +- `lib add book `: Add a new book to the library. +- `lib get hrs`: Retrieve library operating hours. +- `lib rent `: Rent a book from the library. +- `lib add member `: Add a new member to the library (admin privilege required). +- `lib rent `: Rent a book for a specific member. +- `lib get available books`: View available books for rental. +- `lib remove member `: Remove a member from the library (admin privilege required). +- `lib return `: Return a rented book to the library. + +## Getting Started + +To start using our system, simply run the main class `MyApp` and follow the prompts. + +## Conclusion + +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! \ No newline at end of file diff --git a/Answers/_40230112134/pom.xml b/Answers/_40230112134/pom.xml new file mode 100644 index 0000000..2162428 --- /dev/null +++ b/Answers/_40230112134/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + _40230112134 + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Book.java b/Answers/_40230112134/src/main/java/org/example/Book.java new file mode 100644 index 0000000..1b938ee --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Book.java @@ -0,0 +1,27 @@ +package org.example; + +import java.util.*; + +public class Book extends UniqueID { + private String IDBook ; + private String Title , Author , Description; + private ArrayList Total = new ArrayList<>(); + private boolean AvailabilityStatus; + public Book() + { + this.AvailabilityStatus = true; + this.IDBook = getUniqueIDString(); + } + public ArrayList getTotal() { return Total; } + public void setTotal(ArrayList total) { Total = total; } + public String getIDBook() { return IDBook; } + public void setIDBook(String IDBook) { this.IDBook = IDBook; } + public boolean getAvailabilityStatus(){ return AvailabilityStatus; } + public void setAvailabilityStatus(boolean availabilityStatus) { AvailabilityStatus = availabilityStatus; } + public void setAuthor(String author) { Author = author; } + public String getAuthor() { return Author; } + public String getDescription() { return Description; } + public void setDescription(String description) { Description = description; } + public void setTitle(String title) { Title = title; } + public String getTitle() { return Title; } +} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/Library.java b/Answers/_40230112134/src/main/java/org/example/Library.java new file mode 100644 index 0000000..a628bfa --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Library.java @@ -0,0 +1,216 @@ +package org.example; + +import java.io.*; +import java.util.*; + +public class Library { + NormalUser normalUser = new NormalUser(); + Admin admin = new Admin(); + User user = new User(); + private final String LibraryName; + private final String OperatingHours; + private final int CapacityBook; + private final int CapacityUser; +// private final boolean BookRepository; + public Library(){ + this.LibraryName = "(-_-)(HOMA)(-_-)"; + this.OperatingHours = "9 a.m. - 9 p.m."; + this.CapacityBook = 50; + this.CapacityUser = 25; +// this.BookRepository = ChapFileBook(); + } + public int getCapacityUser() { return CapacityUser; } +// public boolean getBookRepository() { return BookRepository; } + public int getCapacityBook() { return CapacityBook; } + public String getOperatingHours() { return OperatingHours; } + public String getLibraryName() { return LibraryName; } + public void ReadFileNormalUser(String filepath) { + normalUser.getPeople().clear(); + ArrayList test = new ArrayList<>(); + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(filepath)); + String line; + normalUser.getPeople().clear(); + while ((line = bufferedReader.readLine()) != null) + { + test.add(line); + } + bufferedReader.close(); + } catch (IOException r){ + System.out.println("An error occurred."); + } + normalUser.setPeople(test); + } + public void WriteFileNormalUser(String filepath) { + try { + FileWriter writer = new FileWriter(filepath); + BufferedWriter bufferedWriter = new BufferedWriter(writer); + for (String temp : normalUser.getPeople()) + { + bufferedWriter.write(temp); + bufferedWriter.newLine(); + } + bufferedWriter.close(); + } catch (IOException e){ + System.out.println("Wrong"); + } + } + public void AddNormalUser(String studentID) { +// ReadFileNormalUser("NormalUser.txt"); + normalUser.setIDUser(studentID); + System.out.println("Enter the your name:"); + Scanner scanner = new Scanner(System.in); + normalUser.setName(scanner.nextLine()); + boolean flag = true; + while (flag) + { + System.out.println("Enter your phone number"); + String temp = scanner.nextLine(); + char[] tem = temp.toCharArray(); + for (char c : tem) + { + if (c < 48 || c > 57) + { + System.out.println("You entered incorrectly\n" + "try again:"); + break; + } + else + { + flag = false; + normalUser.setPhoneNumber(temp); + } + } + } + for (int i = 0; i < normalUser.getPeople().size(); i++) + { + String[] list = normalUser.getPeople().get(i).split("/"); + if (Objects.equals(normalUser.getName(), list[1]) || Objects.equals(normalUser.getPhoneNumber(), list[2])) + { + System.out.println("you can not add the user"); + System.out.println("because we have that"); + } + else + { +// normalUser.setUniqueID(normalUser.FindBigID(normalUser.getPeople())); + normalUser.getPeople().add(normalUser.getIDUser() + "/" + normalUser.getName() + "/" + normalUser.getPhoneNumber() + "/" + normalUser.getFormattedDateTime()); + System.out.println("The user has been successfully added"); + System.out.println("Your Unique ID is : " + normalUser.getIDUser()); + break; + } + } + if (normalUser.getPeople().isEmpty()) { + ArrayList test = new ArrayList<>(); + test.add((normalUser.getIDUser()) + "/" + normalUser.getName() + "/" + normalUser.getPhoneNumber() + "/" + normalUser.getFormattedDateTime()); + normalUser.setPeople(test); + System.out.println("The user has been successfully added"); + System.out.println("Your Unique ID is : " + normalUser.getIDUser()); + } + WriteFileNormalUser("Normaluser.txt"); + } + public void DeleteNormalUser(String number) { + for (int i = 0; i < normalUser.getPeople().size(); i++) + { + 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; + } + } + } + public void ChapFileUser() { + for (int i = 0; i < normalUser.getPeople().size(); i++) + { + String[] list = normalUser.getPeople().get(i).split("/"); + System.out.println("ID: " + list[0] + " _ Name: " + list[1] + " _ Phone number: " + list[2] + " _ Time to enter the library: " + list[3]); + } + } + public void CLIComment() { + boolean flag = true; + user.ReadFileBook("Book.txt"); + ReadFileNormalUser("Normaluser.txt"); + while (flag) { + System.out.println(getLibraryName() + " How can I help you???!!!"); + System.out.println("lib add book "); + System.out.println("lib get hrs"); + System.out.println("lib rent "); + System.out.println("lib add member "); + System.out.println("lib get available books"); + System.out.println("lib get available users "); + System.out.println("lib remove member "); + System.out.println("lib return "); + System.out.println("lib exit"); + System.out.println("Enter your comment --->"); + Scanner scanner = new Scanner(System.in); + String comment = scanner.nextLine(); + if (Objects.equals(comment, "") || Objects.equals(comment, " ")) + { + flag = true; + continue; + } + 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], "book")) + { + user.AddBook(list[3] , list[4] , list[5]); + } + 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) + { + user.Rent(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("**************************"); + } + 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")) + { + user.ReturnBook(list[2]); + } + } + } + user.WriteFileBook("Book.txt"); + WriteFileNormalUser("Normaluser.txt"); + } +} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/MyApp.java b/Answers/_40230112134/src/main/java/org/example/MyApp.java new file mode 100644 index 0000000..5314180 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/MyApp.java @@ -0,0 +1,8 @@ +package org.example; + +public class MyApp extends UniqueID{ + public static void main(String[] args) { + Library library = new Library(); + library.CLIComment(); + } +} \ 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 new file mode 100644 index 0000000..9b19a26 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/Rent.java @@ -0,0 +1,19 @@ +package org.example; + +import java.io.*; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.*; + +public class Rent { + Book book ; + User user ; + LocalDateTime currentDateTime = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private final String RentalDate ; + public String getRentalDate() { return RentalDate; } + public Rent() + { + RentalDate = currentDateTime.format(formatter); + } +} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/UniqueID.java b/Answers/_40230112134/src/main/java/org/example/UniqueID.java new file mode 100644 index 0000000..986dbae --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/UniqueID.java @@ -0,0 +1,17 @@ +package org.example; + +import java.util.Random; + +public class UniqueID { + Random random = new Random(); + private int UniqueID = random.nextInt(1000) + 1; + public String getUniqueIDString() { + return String.valueOf(this.UniqueID); + } + public int getUniqueIDInt() { + return this.UniqueID; + } + public void setUniqueID(int uniqueID) { + this.UniqueID = uniqueID + 1; + } +} \ No newline at end of file diff --git a/Answers/_40230112134/src/main/java/org/example/User.java b/Answers/_40230112134/src/main/java/org/example/User.java new file mode 100644 index 0000000..7df5470 --- /dev/null +++ b/Answers/_40230112134/src/main/java/org/example/User.java @@ -0,0 +1,211 @@ +package org.example; + +import java.io.*; +import java.time.*; +import java.time.format.*; +import java.util.*; + +public class User extends UniqueID { + Book book = new Book(); + Rent rent = new Rent(); + private String Name; + private String IDUser; + private String PhoneNumber; + private ArrayList people = new ArrayList<>(); + public ArrayList getPeople() { return people; } + public void setPeople(ArrayList people) { this.people = people; } + public String getPhoneNumber() { + return PhoneNumber; + } + public void setPhoneNumber(String phoneNumber) { + PhoneNumber = phoneNumber; + } + public String getIDUser() { + return IDUser; + } + public void setIDUser(String IDUser) { + this.IDUser = IDUser; + } + public String getName() { + return Name; + } + public void setName(String name) { + Name = name; + } + public void WriteFileBook(String filepath) + { + try { + FileWriter writer = new FileWriter(filepath); + BufferedWriter bufferedWriter = new BufferedWriter(writer); + for (String temp : book.getTotal()) + { + bufferedWriter.write(temp); + bufferedWriter.newLine(); + } + bufferedWriter.close(); + } catch (IOException e){ + System.out.println("Wrong"); + } + } + public void ReadFileBook(String filepath) + { + ArrayList test = new ArrayList<>(); + book.getTotal().clear(); + try { + BufferedReader bufferedReader = new BufferedReader(new FileReader(filepath)); + String line; + while ((line = bufferedReader.readLine()) != null) + { + test.add(line); + } + bufferedReader.close(); + } catch (IOException r){ + System.out.println("An error occurred."); + } + book.setTotal(test); + } + public void AddBook(String name , String author , String des) + { + book.setIDBook(String.valueOf(getUniqueIDInt() + 1)); + book.setTitle(name); + book.setAuthor(author); + book.setDescription(des); + book.setAvailabilityStatus(true); + for (int i = 0; i < book.getTotal().size(); i++) + { + String[] list = book.getTotal().get(i).split("/"); + if (Objects.equals(book.getTitle(), list[1]) || Objects.equals(book.getDescription(), list[3])) + { + System.out.println("you can not add the book"); + System.out.println("because we have that"); + } + else + { +// setUniqueID(FindBigID(book.getTotal())); + book.getTotal().add(book.getIDBook() + "/" + book.getTitle() + "/" + book.getAuthor() + "/" + book.getDescription() + "/" + book.getAvailabilityStatus()); + System.out.println("The book has been successfully added"); + System.out.println("Your Unique ID is : " + getUniqueIDInt()); + break; + } + } + if (book.getTotal().isEmpty()) { + setUniqueID(0); + book.getTotal().add(book.getIDBook() + "/" + book.getTitle() + "/" + book.getAuthor() + "/" + book.getDescription() + "/" + book.getAvailabilityStatus()); + System.out.println("The book has been successfully added"); + System.out.println("Your Unique ID is : " + book.getIDBook()); + } + } + public void ChapFileBook() + { + for (int i = 0; i < book.getTotal().size(); i++) + { + String[] list = book.getTotal().get(i).split("/"); + if (Objects.equals(list[4], "true")) + { + System.out.println("ID: " + list[0] + " _ Name: " + list[1] + " _ Author: " + list[2] + " _ AvailabilityStatus: " + list[4]); + } + } + } + public void SearchBook(String sentence) + { +// boolean flag = false; +// ReadFileBook("Book.txt"); +// char[] word = sentence.toCharArray(); +// for (int i = 0; i < book.getTotal().size(); i++) +// { +// char[] jomle = book.getTotal().get(i).toCharArray(); +// for (int j = 0; j < jomle.length; j++) +// { +// for (int k = 0; k < word.length; k++) +// { +// if (word[k] == jomle[j]) +// { +// flag = true; +// } +// } +// } +// if (flag) +// { +// flag = false; +// String[] list = book.getTotal().get(i).split("/"); +// System.out.println("Your ID book: " + list[0]); +// System.out.println("Your Title: " + list[1]); +// System.out.println("Your Author: " + list[2]); +// System.out.println("Your Description: " + list[3]); +// System.out.println("Your Availability Status: " + list[4]); +// } +// } +// WriteFileBook("Book.txt"); + } + public void Delete(String number) + { +// for (int i = 0; i < book.getTotal().size(); i++) +// { +// String line1 = book.getTotal().get(i); +// String[] list = line1.split("/"); +// if (Objects.equals(list[0], number)) +// { +// System.out.println("The deletion was successful"); +// book.getTotal().remove(i); +// break; +// } +// } +// book.setTotal(book.getTotal()); + } + public void Rent(String name) + { + for (int i = 0; i < book.getTotal().size(); i++) + { + String[] list = book.getTotal().get(i).split("/"); + if (Objects.equals(list[1],name)) + { + if (Objects.equals(list[4],"true")) + { + book.getTotal().remove(i); + System.out.println("The book has been successfully rented."); + System.out.println("enjoy , Bye."); + String test = list[0] + "/" + list[1] + "/" + list[2] + "/" + list[3] + "/" + rent.getRentalDate() ; + book.getTotal().add(test); + break; + } + else + { + System.out.println("you can not rent this book because the book rented"); + } + } + } + } + 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 test = list[0] + "/" + list[1] + "/" + list[2] + "/" + list[3] + "/" + "true" ; + book.getTotal().add(test); + break; + } + } + } +} +class NormalUser extends User { + + LocalDateTime currentDateTime = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private final String UserDate; + public NormalUser() { + UserDate = currentDateTime.format(formatter); + } + public String getFormattedDateTime() { return UserDate; } +} +class Admin extends User { + private final String Password; + public Admin() + { + this.Password = "8488"; + } + public String getPassword() {return Password;} +} \ No newline at end of file