From 48bf05d676365a01e728c838e12259ee8b1b13c6 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Wed, 1 May 2024 12:44:37 +0330 Subject: [PATCH 1/7] initial project --- .idea/.gitignore | 8 ++++++++ .idea/Library-Management-System.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 37 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Library-Management-System.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Library-Management-System.iml b/.idea/Library-Management-System.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Library-Management-System.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2e1b46d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From 42c558d14c2edabe69f8836b6627ed294b348672 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Thu, 9 May 2024 15:49:52 +0330 Subject: [PATCH 2/7] Save book information --- .idea/Library-Management-System.iml | 4 +- .../40230212031/src/com/Library/Admin.java | 4 ++ Answers/40230212031/src/com/Library/Book.java | 49 +++++++++++++++++++ Answers/40230212031/src/com/Library/CLI.java | 4 ++ .../40230212031/src/com/Library/Library.java | 4 ++ .../src/com/Library/NormalUser.java | 4 ++ Answers/40230212031/src/com/Library/Rent.java | 4 ++ Answers/40230212031/src/com/Library/User.java | 4 ++ Answers/Add Your Projects Here.txt | 0 9 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Answers/40230212031/src/com/Library/Admin.java create mode 100644 Answers/40230212031/src/com/Library/Book.java create mode 100644 Answers/40230212031/src/com/Library/CLI.java create mode 100644 Answers/40230212031/src/com/Library/Library.java create mode 100644 Answers/40230212031/src/com/Library/NormalUser.java create mode 100644 Answers/40230212031/src/com/Library/Rent.java create mode 100644 Answers/40230212031/src/com/Library/User.java delete mode 100644 Answers/Add Your Projects Here.txt diff --git a/.idea/Library-Management-System.iml b/.idea/Library-Management-System.iml index d6ebd48..a2c945f 100644 --- a/.idea/Library-Management-System.iml +++ b/.idea/Library-Management-System.iml @@ -2,7 +2,9 @@ - + + + diff --git a/Answers/40230212031/src/com/Library/Admin.java b/Answers/40230212031/src/com/Library/Admin.java new file mode 100644 index 0000000..02be5c1 --- /dev/null +++ b/Answers/40230212031/src/com/Library/Admin.java @@ -0,0 +1,4 @@ +package com.Library; + +public class Admin { +} diff --git a/Answers/40230212031/src/com/Library/Book.java b/Answers/40230212031/src/com/Library/Book.java new file mode 100644 index 0000000..d0645ae --- /dev/null +++ b/Answers/40230212031/src/com/Library/Book.java @@ -0,0 +1,49 @@ +package com.Library; +import java.util.UUID; + +public class Book { + private String bookID; + private String title; + private String author; + private boolean availabillity; + private String description; + public Book(){}//برای ساخت object بدون نیاز به اطلاعات قبلی + public Book(String title,String author,String description){ + this.title = title; + this.author = author; + this.availabillity = true; + this.description = description; + this.bookId = BookID(); + } +// برای گرفتن مقادیر ازgetter +// برای تغیر ویژگی ها از setter +public String getBookID(){ + return bookID; +} +public String getTitle(){ + return title; +} + public String getAuthor() { + return author; + } + public String getDescription() { + return description; + } + public void setTitle(String title) { + this.title = title; + } + public void setAuthor(String author) { + this.author = author; + } + public void setAvailability(boolean availability) { + this.availability = availability; + } + public void setDescription(String description) { + this.description = description; + } + public UUID BookID() { + return UUID.randomUUID(); // تولید یک ID یکتا به صورت تصادفی + + } +} + diff --git a/Answers/40230212031/src/com/Library/CLI.java b/Answers/40230212031/src/com/Library/CLI.java new file mode 100644 index 0000000..7463a61 --- /dev/null +++ b/Answers/40230212031/src/com/Library/CLI.java @@ -0,0 +1,4 @@ +package com.Library; + +public class CLI { +} diff --git a/Answers/40230212031/src/com/Library/Library.java b/Answers/40230212031/src/com/Library/Library.java new file mode 100644 index 0000000..2334e05 --- /dev/null +++ b/Answers/40230212031/src/com/Library/Library.java @@ -0,0 +1,4 @@ +package com.Library; + +public class Library { +} diff --git a/Answers/40230212031/src/com/Library/NormalUser.java b/Answers/40230212031/src/com/Library/NormalUser.java new file mode 100644 index 0000000..9cb8869 --- /dev/null +++ b/Answers/40230212031/src/com/Library/NormalUser.java @@ -0,0 +1,4 @@ +package com.Library; + +public class NormalUser { +} diff --git a/Answers/40230212031/src/com/Library/Rent.java b/Answers/40230212031/src/com/Library/Rent.java new file mode 100644 index 0000000..76ceede --- /dev/null +++ b/Answers/40230212031/src/com/Library/Rent.java @@ -0,0 +1,4 @@ +package com.Library; + +public class Rent { +} diff --git a/Answers/40230212031/src/com/Library/User.java b/Answers/40230212031/src/com/Library/User.java new file mode 100644 index 0000000..0a3030e --- /dev/null +++ b/Answers/40230212031/src/com/Library/User.java @@ -0,0 +1,4 @@ +package com.Library; + +public class User { +} diff --git a/Answers/Add Your Projects Here.txt b/Answers/Add Your Projects Here.txt deleted file mode 100644 index e69de29..0000000 From 3c0a809856b8bd3bda884ac5e58a3269cbb9a566 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Fri, 10 May 2024 01:53:21 +0330 Subject: [PATCH 3/7] The rental class done, and the library class done up to the rental method section --- Answers/40230212031/src/com/Library/Book.java | 14 ++-- .../40230212031/src/com/Library/Library.java | 84 +++++++++++++++++++ Answers/40230212031/src/com/Library/Rent.java | 27 +++++- 3 files changed, 119 insertions(+), 6 deletions(-) diff --git a/Answers/40230212031/src/com/Library/Book.java b/Answers/40230212031/src/com/Library/Book.java index d0645ae..6187a82 100644 --- a/Answers/40230212031/src/com/Library/Book.java +++ b/Answers/40230212031/src/com/Library/Book.java @@ -5,15 +5,15 @@ public class Book { private String bookID; private String title; private String author; - private boolean availabillity; + private boolean exist; private String description; public Book(){}//برای ساخت object بدون نیاز به اطلاعات قبلی public Book(String title,String author,String description){ this.title = title; this.author = author; - this.availabillity = true; + this.exist = true; this.description = description; - this.bookId = BookID(); + this.bookID = String.valueOf(BookID());// این متد مقدار را به رشته تبدیل میکند } // برای گرفتن مقادیر ازgetter // برای تغیر ویژگی ها از setter @@ -35,8 +35,12 @@ public void setTitle(String title) { public void setAuthor(String author) { this.author = author; } - public void setAvailability(boolean availability) { - this.availability = availability; + public boolean isExist() { + return exist; + } + + public void setExist(boolean exist) { + this.exist = exist; } public void setDescription(String description) { this.description = description; diff --git a/Answers/40230212031/src/com/Library/Library.java b/Answers/40230212031/src/com/Library/Library.java index 2334e05..d51d91b 100644 --- a/Answers/40230212031/src/com/Library/Library.java +++ b/Answers/40230212031/src/com/Library/Library.java @@ -1,4 +1,88 @@ package com.Library; +import java.util.ArrayList; +import java.util.List; +import java.time.LocalDate; public class Library { + private static final String BOOKS_FILE = "data/books.xml"; + private static final String USERS_FILE = "data/users.xml"; + private static final String RENTALS_FILE = "data/rentals.xml"; + + private String name; + private int vacancy; + private String businessHours; + + private List booksList; + private List userList; + private List rentalList; + + public Library(String name, int vacancy, String businessHours) { + this.name = name; + this.vacancy = vacancy; + this.businessHours = businessHours; + this.booksList = new ArrayList<>(); + this.userList = new ArrayList<>(); + this.rentalList = new ArrayList<>(); + + } + + public String getName() { + return name; + } + + public int getVacancy() { + return vacancy; + } + + public String getBusinessHours() { + return businessHours; + } + public void addBook(Book book) { + booksList.add(book); + saveBooks(); + } + public List getBooks() { + return booksList; + } + public List getBooksList() { + List libraryBook = new ArrayList<>(); + for (int i = 0; i < booksList.size(); i++) { + Book book = booksList.get(i); + if (book.isExist()) { + libraryBook.add(book); + } + } + return libraryBook; + } + //////////////////////////////////////////////////////////// + public void adduser(User user){ + userList.add(user); + saveUser(); + } + public List getUser(){ + return userList; + } + ////////////////////////////////////////////////////////////// + public void rentBook(Book book, User user) { + if (!book.isExist()) { + System.out.println("Sorry ^--^ : the book is currently not available for rental."); + return; + } else { + + String rentalDate = LocalDate.now().toString(); + Rent rent = new Rent(book, user, rentalDate); + rentalList.add(rent); + book.setExist(false); + + saveBooks(); + saveRentals(); + + System.out.println("Book rented successfully!"); + } + } + private void saveBooks () { + } + } } + + diff --git a/Answers/40230212031/src/com/Library/Rent.java b/Answers/40230212031/src/com/Library/Rent.java index 76ceede..8433384 100644 --- a/Answers/40230212031/src/com/Library/Rent.java +++ b/Answers/40230212031/src/com/Library/Rent.java @@ -1,4 +1,29 @@ package com.Library; public class Rent { -} + private Book book ; + private User user; + private int rentalId;//آیدی برای اجاره کتاب که تکراری نشود!!! + private String rentalDate; //مدت زمان rent + + private static int nextRentalID =1; // مقدار پیش فرض یا اولیه آیدی + public Rent(Book book, User user, String rentalDate) { + this.book = book; + this.user = user; + this.rentalId = nextRental; + nextRental++; + this.rentalDate = rentalDate; + } + public Book getBook(){ + return book; + } + public User getUser(){ + return rentalId; + } + public int getRentalId(){ + return rentalId; + } + public String getRentalDate() { + return rentalDate; + } + } From 9af4a1aac0430043dc65e233f5cc516502092fa0 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Fri, 10 May 2024 16:16:33 +0330 Subject: [PATCH 4/7] The library class was finished and the user and admin classes were also completed --- .idea/Library-Management-System.iml | 9 +++------ .idea/compiler.xml | 13 +++++++++++++ .idea/libraries/KotlinJavaRuntime.xml | 7 +++++++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/libraries/KotlinJavaRuntime.xml diff --git a/.idea/Library-Management-System.iml b/.idea/Library-Management-System.iml index a2c945f..776401a 100644 --- a/.idea/Library-Management-System.iml +++ b/.idea/Library-Management-System.iml @@ -1,11 +1,8 @@ - - - - + + + - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..e0236b2 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..d2eaa8c --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file From 2e074614748bd7b524fe9378e747c2af9f0a04a3 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Thu, 16 May 2024 03:34:54 +0330 Subject: [PATCH 5/7] The first part of the cli class --- .idea/inspectionProfiles/Project_Default.xml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..cd83845 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file From 33bb8acb2fa8eb0bf49d2bc4f7549334f88d41f2 Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Thu, 16 May 2024 17:57:00 +0330 Subject: [PATCH 6/7] The cli class is completed and the application class is also created --- Answers/40230212031/src/com/Library/App.java | 2 ++ Answers/data/books.txt | 0 Answers/data/rentals.txt | 0 Answers/data/users.txt | 0 4 files changed, 2 insertions(+) create mode 100644 Answers/40230212031/src/com/Library/App.java create mode 100644 Answers/data/books.txt create mode 100644 Answers/data/rentals.txt create mode 100644 Answers/data/users.txt diff --git a/Answers/40230212031/src/com/Library/App.java b/Answers/40230212031/src/com/Library/App.java new file mode 100644 index 0000000..b021daf --- /dev/null +++ b/Answers/40230212031/src/com/Library/App.java @@ -0,0 +1,2 @@ +package com.Library;public class App { +} diff --git a/Answers/data/books.txt b/Answers/data/books.txt new file mode 100644 index 0000000..e69de29 diff --git a/Answers/data/rentals.txt b/Answers/data/rentals.txt new file mode 100644 index 0000000..e69de29 diff --git a/Answers/data/users.txt b/Answers/data/users.txt new file mode 100644 index 0000000..e69de29 From 85d94beda3abf18685f061dd0fd2fa1c0505b97d Mon Sep 17 00:00:00 2001 From: Amirhoseinhmd83 Date: Thu, 16 May 2024 22:32:32 +0330 Subject: [PATCH 7/7] Fixing program bugs and adding some more options --- {Answers/data => data}/books.txt | 0 {Answers/data => data}/rentals.txt | 0 {Answers/data => data}/users.txt | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {Answers/data => data}/books.txt (100%) rename {Answers/data => data}/rentals.txt (100%) rename {Answers/data => data}/users.txt (100%) diff --git a/Answers/data/books.txt b/data/books.txt similarity index 100% rename from Answers/data/books.txt rename to data/books.txt diff --git a/Answers/data/rentals.txt b/data/rentals.txt similarity index 100% rename from Answers/data/rentals.txt rename to data/rentals.txt diff --git a/Answers/data/users.txt b/data/users.txt similarity index 100% rename from Answers/data/users.txt rename to data/users.txt