diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..639900d --- /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..d5f086e --- /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..d7f209d --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e1021c9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1715508570372 + + + + + + + \ No newline at end of file diff --git a/Answers/Admin.java b/Answers/Admin.java new file mode 100644 index 0000000..adb6867 --- /dev/null +++ b/Answers/Admin.java @@ -0,0 +1,10 @@ +import java.util.HashMap; + +public class Admin extends User { + HashMap adminsave=new HashMap<>(); + public void addAdmin(String adname,String adpass) { + uname=adname; + userpass=adpass; + adminsave.put(adname, adpass); + } +} diff --git a/Answers/Book.java b/Answers/Book.java new file mode 100644 index 0000000..d3e0b0a --- /dev/null +++ b/Answers/Book.java @@ -0,0 +1,18 @@ +import java.util.HashMap; + +public class Book { + int bookid=1; + String bookname; + String author; + String description; + boolean dastresi=false; + HashMap writerdooni=new HashMap<>(); + HashMap subdooni=new HashMap<>(); + public void bmaker(String bookname, String author, String description) { + this.bookname = bookname; + this.author = author; + this.description = description; + bookid++; + this.dastresi=true; + } +} \ No newline at end of file diff --git a/Answers/CLI.java b/Answers/CLI.java new file mode 100644 index 0000000..a74a753 --- /dev/null +++ b/Answers/CLI.java @@ -0,0 +1,76 @@ +public class CLI { + Library ketkh=new Library(); + Rent r=new Rent(); + Book bok=new Book(); + Normaluser nu=new Normaluser(); + Admin addd=new Admin(); + public void libaddbook(String bname,String writer,String sub) { + if (!(ketkh.bookesm.contains(bname) && bok.writerdooni.containsValue(writer) && bok.subdooni.containsValue(sub))) { + Book b = new Book(); + b.bmaker(bname, writer, sub); + ketkh.mylib.add(b); + ketkh.bookesm.add(b.bookname); + bok.writerdooni.put(bname,writer); + bok.subdooni.put(bname,sub); + } else { + System.out.println("this book already exists!"); + } + } + public void libgethrs() { + System.out.println("az 9:00 sobh ta 11:00 shab."); + } + public void librent(String bname,String mn1) { + r.rentmem.put(mn1, nu.memidsave.get(mn1)); + if (ketkh.bookesm.contains(bname)) { + r.rentsaz(bname); + ketkh.bookesm.remove(bname); + System.out.println("book is rented!"); + } else { + System.out.println("book not found!"); + } + } + public void libaddmember(String sname,String password) { + if (nu.mempasssave.containsKey(sname)==false && nu.mempasssave.containsValue(password)==false) { + nu.makeaccount(sname, password); + System.out.println("member added!"); + } else { + System.out.println("this member already exists!"); + } + } + public void librentforamember(String boname,String memn) { + if (nu.mempasssave.containsKey(memn)) { + librent(boname,memn); + } else { + System.out.println("user not found!"); + } + } + public void libgetavailablebooks() { + System.out.println(ketkh.bookesm); + } + public void libremovemember(String memname) { + if (nu.mempasssave.containsKey(memname)) { + nu.mempasssave.remove(memname); + nu.memidsave.remove(memname); + if (addd.adminsave.containsKey(memname)) { + addd.adminsave.remove(memname); + } + if (r.rentmem.containsKey(memname)) { + r.rentmem.remove(memname); + } + System.out.println("member removed."); + } else { + System.out.println("user not found!"); + } + } + public void libreturn(String bookn) { + if (r.bookrent.containsKey(bookn)) { + r.bookrent.remove(bookn); + ketkh.bookesm.add(bookn); + System.out.println("book returned."); + } else if (ketkh.bookesm.contains(bookn)) { + System.out.println("the book hasnt been rented yet!"); + } else { + System.out.println("this book hasnt been in our library!"); + } + } +} \ No newline at end of file diff --git a/Answers/Library.java b/Answers/Library.java new file mode 100644 index 0000000..e6d2d6a --- /dev/null +++ b/Answers/Library.java @@ -0,0 +1,7 @@ +import java.util.ArrayList; +public class Library { + String libname = "nooshirvanilib"; + ArrayList mylib = new ArrayList<>(); + ArrayList bookesm=new ArrayList<>(); + int cap=bookesm.size(); +} \ No newline at end of file diff --git a/Answers/Myapp.java b/Answers/Myapp.java new file mode 100644 index 0000000..9fec89c --- /dev/null +++ b/Answers/Myapp.java @@ -0,0 +1,6 @@ +public class Myapp { + public static void main(String[] args) { + Run obj=new Run(); + obj.runner(); + } +} diff --git a/Answers/Normaluser.java b/Answers/Normaluser.java new file mode 100644 index 0000000..1378be7 --- /dev/null +++ b/Answers/Normaluser.java @@ -0,0 +1,12 @@ +import java.time.LocalDate; + +public class Normaluser extends User { + LocalDate logindate=LocalDate.now(); + public void makeaccount(String lname,String lpass) { + uname = lname; + userpass = lpass; + memidsave.put(lname,userid); + userid++; + mempasssave.put(lname,lpass); + } +} \ No newline at end of file diff --git a/Answers/Rent.java b/Answers/Rent.java new file mode 100644 index 0000000..4865e3a --- /dev/null +++ b/Answers/Rent.java @@ -0,0 +1,13 @@ +import java.time.LocalDate; +import java.util.HashMap; + +public class Rent { + int rentid=1; + LocalDate rentdate = LocalDate.now(); + HashMap bookrent=new HashMap<>(); + HashMap rentmem=new HashMap<>(); + public void rentsaz(String esmb) { + bookrent.put(esmb,rentid); + rentid++; + } +} \ No newline at end of file diff --git a/Answers/Run.java b/Answers/Run.java new file mode 100644 index 0000000..b33d65b --- /dev/null +++ b/Answers/Run.java @@ -0,0 +1,206 @@ +import java.time.LocalTime; +import java.util.Scanner; + +public class Run { + CLI tab=new CLI(); + LocalTime t=LocalTime.now(); + LocalTime t1=LocalTime.of(9,00,00); + LocalTime t2=LocalTime.of(23,00,00); + public void runner() { + Scanner sc=new Scanner(System.in); + Scanner sc2=new Scanner(System.in); + if (t.isAfter(t1) && t.isBefore(t2)) { + tab.nu.makeaccount("Aran Rafiaei","40230212043"); + tab.addd.addAdmin("Aran Rafiaei","40230212043"); + tab.libaddbook("binavayan","Victor Hogo","ketab dar morede chand binavast."); + tab.libaddbook("bishoori","Xavier Crement","ye ketab dar morede bishoori."); + tab.libaddbook("nooshirvani kojast","nashenas","addresse nooshivani be zaban haye mokhtalef."); + System.out.println("Welcome to Nooshirvani library! choose the number of one of options below."); + System.out.println("1.Yes"); + System.out.println("2.No"+"\n"); + System.out.print("Are you Admin: "); + String name=""; + for (;;) { + String yn=sc.nextLine(); + boolean l=false; + switch (yn) { + case "1": + System.out.print("enter the password: "); + for (;;) { + String pass=sc.nextLine(); + if (tab.addd.adminsave.containsValue(pass)) { + name="Aran Rafiaei"; + break; + } else { + System.out.print("admin not found!try another password: "); + } + } + l=true; + break; + case "2": + System.out.println("you must make account.first, enter your name below."); + System.out.print("my name is: "); + for (;;) { + name=sc.nextLine(); + if (tab.nu.mempasssave.containsKey(name)==false) { + break; + } else { + System.out.print("your name must be unique.try another: "); + } + } + System.out.print("enter a password: "); + String pasw; + while (true) { + pasw=sc2.nextLine(); + if (tab.nu.mempasssave.containsValue(pasw)) { + System.out.print("this password is not unique: "); + } else { + break; + } + } + tab.nu.makeaccount(name,pasw); + l=true; + System.out.println("now you have an account."); + break; + default: + System.out.print("wrong option.try again: "); + break; + } + if (l==true) { + break; + } + } + System.out.println("here they are our options of library.choose the number of one of them."); + boolean m=true; + for (;;) { + if (m) { + System.out.println("1.add a book"); + System.out.println("2.get work hours"); + System.out.println("3.rent a book"); + System.out.println("4.add a member (admins only)"); + System.out.println("5.rent a book for a member"); + System.out.println("6.see available books"); + System.out.println("7.remove a member (admins only)"); + System.out.println("8.return a book"); + System.out.println("9.exit"); + System.out.print("I choose: "); + } + boolean kh=false; + String op=sc.nextLine(); + switch (op) { + case "1": + m=true; + System.out.print("enter book name: "); + String bname=sc.nextLine(); + System.out.print("enter the author: "); + String nv=sc.nextLine(); + System.out.print("what is the book about: "); + String caption=sc2.nextLine(); + tab.libaddbook(bname,nv,caption); + if (!(bc.bookesm.contains(bname) && bk.writerdooni.containsValue(nv) && bk.subdooni.containsValue(caption))) { + System.out.println("book added."); + } + break; + case "2": + m=true; + tab.libgethrs(); + break; + case "3": + m=true; + System.out.print("enter the name of the book: "); + String boname=sc.nextLine(); + tab.librent(boname,name); + break; + case "4": + m=true; + System.out.print("enter the admin password: "); + String adminpass=sc.nextLine(); + if (tab.addd.adminsave.containsValue(adminpass)==false) { + System.out.println("seems like you are not admin."); + break; + } + System.out.print("enter a name: "); + String mname= sc.nextLine(); + System.out.print("enter a password: "); + String mpass=sc2.nextLine(); + boolean a=false; + if (tab.nu.mempasssave.containsKey(mname)==false && tab.nu.mempasssave.containsValue(mpass)==false) { + a=true; + } + tab.libaddmember(mname,mpass); + if (a) { + System.out.println("would you like to consider your member as admin?"); + System.out.print("enter yes\\no: "); + for (;;) { + String ans = sc2.nextLine(); + boolean b = false; + switch (ans) { + case "yes": + tab.addd.addAdmin(mname, mpass); + System.out.println("admin added!"); + b = true; + break; + case "no": + b = true; + break; + default: + System.out.print("you must enter \"yes\" or \"no\": "); + break; + } + if (b == true) { + break; + } + } + } + break; + case "5": + m=true; + System.out.print("enter the name: "); + String mename=sc.nextLine(); + System.out.print("enter the name of the book: "); + String bn=sc.nextLine(); + tab.librentforamember(bn,mename); + break; + case "6": + m=true; + tab.libgetavailablebooks(); + break; + case "7": + m=true; + System.out.print("enter the admin password: "); + String pw=sc.nextLine(); + if (tab.addd.adminsave.containsValue(pw)==false) { + System.out.println("seems like you are not admin."); + break; + } + System.out.print("enter the name of member: "); + String rm=sc.nextLine(); + tab.libremovemember(rm); + break; + case "8": + m=true; + System.out.print("enter the name of the book: "); + String rbn=sc.nextLine(); + tab.libreturn(rbn); + break; + case "9": + kh=true; + break; + default: + m=false; + System.out.print("wrong option.try again: "); + break; + } + if (kh) { + System.out.print("see you later."); + break; + } + if (m) { + System.out.println("anything else?"); + } + } + } else { + System.out.println("Sorry,we are closed!"); + } + } +} diff --git a/Answers/User.java b/Answers/User.java new file mode 100644 index 0000000..6fa86a4 --- /dev/null +++ b/Answers/User.java @@ -0,0 +1,9 @@ +import java.util.HashMap; + +public class User { + String uname; + int userid=10; + String userpass; + HashMap mempasssave=new HashMap<>(); + HashMap memidsave=new HashMap<>(); +} diff --git a/Library-Management-System.iml b/Library-Management-System.iml new file mode 100644 index 0000000..27891c9 --- /dev/null +++ b/Library-Management-System.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file