diff --git a/report.txt b/report.txt new file mode 100644 index 0000000..b91ceec --- /dev/null +++ b/report.txt @@ -0,0 +1,8 @@ +Library Management System +in project shamel 5 class ast ke ebaratand az class Main - class Book - class Library - class User - class librarian +class main : bakhsh asli in class ro function runMenu tashkil mide. dar in function ma menu asli ro baraye karbar load mikonim. karbar bayad az beyne 2 gozine users va librarians yeki ro entekhab kone. karbar harkodam ro ke entekhab kone 2 gozine moshabeh barash bala miad ke yeki sign up va digari sign in hastesh ke baraye horkodam function tarif shode. vaghti karbar varede account khodesh beshe gozinehaye jadidi barash load mishe ke in gozine ha baraye user va librarian fargh mikone va in gozineha ba function haye userMenu va librarianMenu load mishe. harkodam az in gozineha ham be surate function tarif shode ke az ruye esme har function mishe be kari ke anjam mide pey bord. dar nahayat function runMenu dar function main seda zade shode. +class Book : in class shamele attribute hayi hastesh ke az esmeshun malume ke chi hastan. baraye hameye in attribute ha function haye getter va setter tarif shode. hamchenin function toString ke etelaat marbut be ketab ro return mikone tarif shode. +va yek function baraye taghir dar dastrest budan ketab ba esme changeAvailableStatus. +class Library: in class bozorgtarin va mohem tarin class ast. dar in class 3 arraylist az books , users va librarians sakhte shode ke darvaghe ma dar in 3 arraylist etelaate marbut be ketabha va karbar ha va ketabdar ha ro zakhire mikonim. in class shamele function haye ziadi hast ke az esme har funciton mitavan be karayi un function pey bord. +class User : ma dar in class 2 attribute baraye user tarif kardim ke ebaratand az String username va String password. baraye in 2 attribute function haye getter va setter tarif kardim. hamchenin yek function changePassword baraye taghir password user tarif kardim. az unjayi ke user mitavanad ketab gharz konad va ketab hayi ke az ketabkhane gharz karde ro pas bedahad , ma yek arraylist rentbooks tarif kardim va 2 function ba nam haye rentBook va returnBook ke in 2 funciton ba tavajoh be esmeshan ketab gharz migiran va ketab gharz gerefte shode az ketabkhune ro pas midan. function toString ham etelaat marbut be user ro be surate yek string return mikone. +class Librarian : in class ham manande class User daraye 2 attribute username va passrword hast. va baraye in 2 attribute function haye getter va setter tarif shode. hamchenin yek function changePassword baraye taghir passsworde librarian tarif shode. function toString niz etelaate marbut be librarian ro return mikone. \ No newline at end of file diff --git a/src/main/java/Book.java b/src/main/java/Book.java index 7cff6f8..f6c6378 100644 --- a/src/main/java/Book.java +++ b/src/main/java/Book.java @@ -1,3 +1,68 @@ public class Book { //Book should contain name,author,year of publish and ISBN + private String name; + private String author; + private int yearOfPublish; + private String ISBN; + private Boolean isAvailable = true; + /* public Book(String name, String author, int yearOfPublish, String ISBN) + { + this.name = name; + this.author = author; + this.yearOfPublish = yearOfPublish; + this.ISBN = ISBN; + }*/ + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public int getYearOfPublish() { + return yearOfPublish; + } + + public void setYearOfPublish(int yearOfPublish) { + this.yearOfPublish = yearOfPublish; + } + + public String getISBN() { + return ISBN; + } + + public void setISBN(String ISBN) { + this.ISBN = ISBN; + } + + public Boolean getAvailable() { + return isAvailable; + } + + public void setAvailable(Boolean available) { + isAvailable = available; + } + + public String toString() + { + return "Name: " + name + " " + + "Author: " + author + " " + + "Year of publish: " + yearOfPublish + "" + + "ISBN: " + ISBN + "" + + "Is available? " + isAvailable; + } + + public void changeAvailableStatus(){ + this.isAvailable = !isAvailable; + } } diff --git a/src/main/java/Librarian.java b/src/main/java/Librarian.java index 321ce3a..68a77da 100644 --- a/src/main/java/Librarian.java +++ b/src/main/java/Librarian.java @@ -1,10 +1,59 @@ -public class Librarian { +import java.util.Scanner; + +public class Librarian +{ /* * The librarian should have a username and a password * The librarian should be able to search users, librarians and books - * The librarian should be able to add\remove\update user add\remove\update_ - _ librarian and add\remove\update book + * The librarian should be able to add\remove\ update user add\remove\ update_ + _ librarian and add\remove\ update book */ + Scanner input = new Scanner(System.in); + + private String username; + private String password; + /* public Librarian(String username, String password) + { + this.username = username; + this.password = password; + }*/ + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void changePassword(){ + System.out.println("Enter your currenct password :"); + String currentPassword = input.nextLine(); + if (currentPassword.equals(getPassword())) + { + System.out.println("Enter your new password :"); + String newPassword = input.nextLine(); + this.password = newPassword; + } + else + { + System.out.println("Wrong password!"); + changePassword(); + } + } + public String toString() + { + return "Librarian's username: " + username + " " + + "Librarian's password: " + password; + } } diff --git a/src/main/java/Library.java b/src/main/java/Library.java index 6c34354..2875c7e 100644 --- a/src/main/java/Library.java +++ b/src/main/java/Library.java @@ -1,3 +1,7 @@ +import java.util.ArrayList; +import java.util.Scanner; +import java.util.HashMap; + public class Library { /* * The library should have a list of books. @@ -7,78 +11,271 @@ public class Library { */ //book related functions + ArrayList books = new ArrayList<>(); + ArrayList users = new ArrayList<>(); + ArrayList librarians = new ArrayList<>(); - public void addBook(){ - //TODO + Scanner input = new Scanner(System.in); + + HashMap numberOfBooks = new HashMap(); + + public void addBook(Book ketab){ + if (!doesBookExist(ketab)) + { + books.add(ketab); + increaseBook(ketab); + } + else + { + System.out.println("We have already had this book!"); + } } - public void removeBook(){ - //TODO + public void removeBook(Book ketab){ + if (doesBookExist(ketab)) + { + for (int i=0; i rentBooks = new ArrayList<>(); + + public void rentBook(Library ketabkhune , Book ketab){ //TODO + if (ketabkhune.doesBookExist(ketab)) + { + if (ketab.getAvailable()) + { + rentBooks.add(ketab); + ketabkhune.updateBook(ketab); + ketabkhune.decreaseBook(ketab); + } + else + { + System.out.println("This book is not available!"); + } + } + else + { + System.out.println("This book does not exist!"); + } + } + public String searchRentBook(Book ketab){ + //TODO + for (int i=0; i