diff --git a/Answers/40230112013/Library Management System/.vscode/settings.json b/Answers/40230112013/Library Management System/.vscode/settings.json new file mode 100644 index 0000000..e112a70 --- /dev/null +++ b/Answers/40230112013/Library Management System/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/Answers/40230112013/Library Management System/LibRepo.txt b/Answers/40230112013/Library Management System/LibRepo.txt new file mode 100644 index 0000000..1497386 Binary files /dev/null and b/Answers/40230112013/Library Management System/LibRepo.txt differ diff --git a/Answers/40230112013/Library Management System/README.md b/Answers/40230112013/Library Management System/README.md new file mode 100644 index 0000000..7c03a53 --- /dev/null +++ b/Answers/40230112013/Library Management System/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/Answers/40230112013/Library Management System/bin/Admin.class b/Answers/40230112013/Library Management System/bin/Admin.class new file mode 100644 index 0000000..56193fa Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/Admin.class differ diff --git a/Answers/40230112013/Library Management System/bin/App.class b/Answers/40230112013/Library Management System/bin/App.class new file mode 100644 index 0000000..ce5a548 Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/App.class differ diff --git a/Answers/40230112013/Library Management System/bin/Book.class b/Answers/40230112013/Library Management System/bin/Book.class new file mode 100644 index 0000000..ae3647a Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/Book.class differ diff --git a/Answers/40230112013/Library Management System/bin/Cli.class b/Answers/40230112013/Library Management System/bin/Cli.class new file mode 100644 index 0000000..8e06716 Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/Cli.class differ diff --git a/Answers/40230112013/Library Management System/bin/Library.class b/Answers/40230112013/Library Management System/bin/Library.class new file mode 100644 index 0000000..6827941 Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/Library.class differ diff --git a/Answers/40230112013/Library Management System/bin/Rent.class b/Answers/40230112013/Library Management System/bin/Rent.class new file mode 100644 index 0000000..7510901 Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/Rent.class differ diff --git a/Answers/40230112013/Library Management System/bin/User.class b/Answers/40230112013/Library Management System/bin/User.class new file mode 100644 index 0000000..b896b91 Binary files /dev/null and b/Answers/40230112013/Library Management System/bin/User.class differ diff --git a/Answers/40230112013/Library Management System/src/Admin.java b/Answers/40230112013/Library Management System/src/Admin.java new file mode 100644 index 0000000..5089642 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/Admin.java @@ -0,0 +1,9 @@ +public class Admin extends User { + public Admin(String name, String surname, String phoneNumber, String userId, String password) { + super(name, surname, phoneNumber, userId, password); + } + + static final String Adminpass = "e"; + + +} diff --git a/Answers/40230112013/Library Management System/src/App.java b/Answers/40230112013/Library Management System/src/App.java new file mode 100644 index 0000000..d3f0ca7 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/App.java @@ -0,0 +1,174 @@ +import java.io.IOException; +import java.util.*; + +public class App { + public static void main(String[] args) throws IOException { + try (Scanner scanner = new Scanner(System.in)) { + int i = 1; + while (i == 1) { + Cli.start(); + switch (scanner.nextInt()) { + case 1: + i = 1; + User us = Cli.avardanuser(); + if (us != null) { + Cli.adps(); + String s = scanner.next(); + if (s.equalsIgnoreCase(Admin.Adminpass)) { + while (i == 1) { + Cli.adminList(); + int j = scanner.nextInt(); + switch (j) { + case 1: + Library.addBook(Cli.getBook()); + System.out.println("*********************\nanjam shod"); + break; + case 2: + Library.showBook(); + break; + case 3: + Library.showUser(); + break; + case 4: + Cli.bfind(); + String h = scanner.next(); + List l = Book.bookfinder(h); + int o=100; + if(l.size()==0){ + System.out.println("yaft nshd "); + break; + } + Cli.gh(); + while (o>l.size()) { + o = scanner.nextInt(); + } + o--; + Cli.rentday(); + boolean ax = true; + if (ax == true) { + Library.rentBook(l.get(o), us, scanner.nextInt()); + ax = false; + } + break; + case 5: + Library.returnBook(us); + break; + case 6: + Library.removeUser(us); + System.exit(0); + break; + case 7: + Cli.bfind(); + String ui = scanner.next(); + List hg = Book.bookfinder(ui); + if(hg.size()==0){ + System.out.println("yaft nshd "); + break; + } + Cli.gh(); + int po=100; + while (po>hg.size()) { + po = scanner.nextInt(); + po--; + } + + Library.removeBook(hg.get(po)); + System.out.println("anjam shod"); + break; + case 8 : + Cli.getHours(); + Cli.getCapacity(); + break; + case 9: + System.exit(0); + break; + default: + break; + } + Cli.edame(); + i = scanner.nextInt(); + } + } else { + System.out.println("admin pass is incorrect"); + } + } else + System.out.println("admin not found"); + break; + case 2: + i = 1; + User uk = Cli.avardanuser(); + if (uk != null) { + while (i == 1) { + Cli.userList(); + int j = scanner.nextInt(); + switch (j) { + case 1: + Library.addBook(Cli.getBook()); + System.out.println("*******************\nanjam shod"); + break; + case 2: + Book.bookfinder("o"); + break; + case 3: + Cli.bfind(); + String h = scanner.next(); + List l = Book.bookfinder(h); + int o=100; + if(l.size()==0){ + System.out.println("yaft nshd "); + break; + } + Cli.gh(); + while (o>l.size()) { + o = scanner.nextInt(); + } + o--; + Cli.rentday(); + boolean ax = true; + if (ax == true) { + Library.rentBook(l.get(o), uk, scanner.nextInt()); + ax = false; + } + break; + case 4: + Library.returnBook(uk); + break; + case 5: + Cli.getCapacity(); + Cli.getHours(); + break; + case 6: + System.exit(0); + case 7: + Library.removeUser(uk); + System.exit(0); + break; + default: + break; + } + } + } else + System.out.println("user not found"); + break; + case 3: + User user = Cli.rgistr(); + Library.addUser(user); + System.out.println("anjam shod"); + break; + case 4: + System.exit(0); + break; + default: + System.out.println("Na motabar"); + break; + } + Cli.edame(); + try { + i = scanner.nextInt(); + } catch (Exception e) { + break; + } + } + } + } +} \ No newline at end of file diff --git a/Answers/40230112013/Library Management System/src/Book.java b/Answers/40230112013/Library Management System/src/Book.java new file mode 100644 index 0000000..ca8e2bf --- /dev/null +++ b/Answers/40230112013/Library Management System/src/Book.java @@ -0,0 +1,76 @@ +import java.util.*; + +public class Book { + private String bookID; + private String title; + private String author; + private boolean isAvailable; + private String description; + + public Book(String title, String author, String description) { + this.bookID = UUID.randomUUID().toString(); + this.title = title; + this.author = author; + this.description = description; + this.isAvailable = true; + } + + public String getBookID() { + return bookID; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public boolean isAvailable() { + return isAvailable; + } + + public void setAvailable(boolean available) { + isAvailable = available; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public String toString1() { + return "Book{" + + "bookID='" + bookID + '\'' + + ", title='" + title + '\'' + + ", author='" + author + '\'' + + ", isAvailable=" + isAvailable + + ", description='" + description + '\'' + + '}'; + } + public static List bookfinder(String t) { + + List me = Library.getrepo(); + List b = new ArrayList(); + int i=1; + for (Book u : me) { + if(u.toString1().contains(t)){ + System.out.println(i +"_" + u.toString1()); + b.add(u); + i++; + } + } + return b; + } +} diff --git a/Answers/40230112013/Library Management System/src/Cli.java b/Answers/40230112013/Library Management System/src/Cli.java new file mode 100644 index 0000000..0eed468 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/Cli.java @@ -0,0 +1,128 @@ +import java.util.*; + +public class Cli { + public static void start() { + System.out.println( + "**********************\nHello to library\nWhat is your role?\n1.Admin\n2.Normaluser\n3.I want to register.\n4.exit"); + } + + public static void adps() { + System.out.println("***********************\nPlease enter admins password"); + } + + public static void edame() { + System.out.println("*****************************\nDo you want to continue\n1.yes\n2.no\n***************************"); + } + + public static void adminList() { + System.out.println("*********************************\n"); + System.out.println("1.add book\n2.see all books"); + System.out.println("3.see all users\n4.rent book"); + System.out.println("5.return book"); + System.out.println("6.del user"); + System.out.println("7.del book\n8.get hours and capacity\n9.exit\n*******************************"); + } + + public static void userList() { + System.out.println("*********************************\n"); + System.out.println("1.add book\n2.search books"); + System.out.println("3.rent book\n4.return book\n5.get hours and capacity\n6.exit\n7.del user\n*************************"); + } + + public static Book getBook() { + + @SuppressWarnings("resource") + Scanner s = new Scanner(System.in); + System.out.println("please enter title:"); + String title = s.nextLine(); + System.out.println("please enter author:"); + String author = s.nextLine(); + System.out.println("please enter description:"); + String description = s.nextLine(); + Book book = new Book(title, author, description); + return book; + } + + public static void bfind() { + System.out.println("Please enter info from book:"); + } + + public static void gh() { + System.out.println("Lotfan shomare vard konid"); + } + + public static User rgistr() { + boolean xj = false; + @SuppressWarnings("resource") + Scanner s = new Scanner(System.in); + String name = ""; + while (!xj) { + System.out.println("please enter name:"); + name = s.nextLine(); + xj = !name.chars().anyMatch(ch -> !Character.isAlphabetic(ch)); + } + String familyname = ""; + xj = false; + while (!xj) { + System.out.println("please enter family name:"); + familyname = s.nextLine(); + xj = !familyname.chars().anyMatch(ch -> !Character.isAlphabetic(ch)); + } + xj = false; + String pn = ""; + while (!xj) { + System.out.println("please enter Phone number:"); + pn = s.nextLine(); + if (pn.length() ==11 && (pn.chars().anyMatch(ch -> !Character.isAlphabetic(ch)) && pn.charAt(0) == '0') ) + xj = true; + } + + System.out.println("please enter password:"); + String pass = s.nextLine(); + xj = false; + String lid = ""; + while (!xj) { + xj = true; + System.out.println("please enter Lib id:"); + lid = s.nextLine(); + for (User cj : Library.getuser()) { + if (cj.getId().equals(lid)) { + System.out.println("The ID is duplicated, please enter again."); + xj = false; + break; + } + } + } + User x = new User(name, familyname, pn, lid, pass); + return x; + } + + public static User avardanuser() { + @SuppressWarnings("resource") + Scanner scanner = new Scanner(System.in); + System.out.println("please enter name or id or phone number:"); + String userInfo = scanner.nextLine(); + System.out.println("Please Enter your password"); + String password = scanner.nextLine(); + List users = Library.getuser(); + for (User user : users) { + if ((user.getPassword().equals(password)) && (userInfo.equalsIgnoreCase(user.getName()) + || userInfo.equalsIgnoreCase(user.getPhoneNumber()) || userInfo.equalsIgnoreCase(user.getId()))) { + return user; + } + } + return null; + } + + public static void rentday() { + System.out.println("How many days to rent?"); + } + + public static void getHours() { + System.out.println("Library hours is 8 am to 6pm"); + } + + public static void getCapacity() { + System.out.println("Library capacity is 100 members"); + } +} diff --git a/Answers/40230112013/Library Management System/src/Library.java b/Answers/40230112013/Library Management System/src/Library.java new file mode 100644 index 0000000..01de0f7 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/Library.java @@ -0,0 +1,80 @@ +import java.util.*; + +public class Library { + private static Map rentRecords = new HashMap(); + static String LibraryName; + int Capacity; + String Operating_hours; + private static List repository = new ArrayList(); + private static List users = new ArrayList(); + + public Library() { + @SuppressWarnings({ "rawtypes", "unused" }) + HashMap rentRecords = new HashMap<>(); + } + + public static void addBook(Book book) { + repository.add(book); + } + + public static void removeBook(Book book) { + repository.remove(book); + + } + + public static void addUser(User user) { + users.add(user); + } + + public static void removeUser(User user) { + users.remove(user); + } + + public static List getrepo() { + return repository; + } + + public static List getuser() { + return users; + } + + public static void rentBook(Book book, User user, int rentDays) { + if (repository.contains(book)) { + Rent rent = new Rent(book, user, rentDays); + rentRecords.put(user, rent); + repository.remove(book); + System.out.println("Book" + book.getTitle() + "from" + user.getName() + "Rented"); + } else { + System.out.println("********************\nBook is not available"); + } + } + + public static void returnBook(User user) { + Rent rent = rentRecords.get(user); + if (rent != null) { + repository.add(rent.getBook()); + rentRecords.remove(user); + System.out.println("The book " + rent.getBook().getTitle() + "ّ From " + user.getName() + " taken back."); + } else { + System.out.println("********************\nreturn book is faild"); + } + } + + public static void showBook() { + int i = 1; + for (Book x : repository) { + String p = x.toString1(); + System.out.println(i + "-" + p); + i++; + } + } + + public static void showUser() { + int i = 1; + for (User x : users) { + String p = x.toString2(); + System.out.println(i + "-" + p); + i++; + } + } +} diff --git a/Answers/40230112013/Library Management System/src/Rent.java b/Answers/40230112013/Library Management System/src/Rent.java new file mode 100644 index 0000000..9ebee98 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/Rent.java @@ -0,0 +1,36 @@ +import java.time.LocalDate; + +public class Rent { + private Book book; + private User user; + private LocalDate dueDate; + + public Rent(Book book, User user, int rentDays) { + this.book = book; + this.user = user; + this.dueDate = LocalDate.now().plusDays(rentDays); + } + public Book getBook() { + return book; + } + + public void setBook(Book book) { + this.book = book; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public LocalDate getDueDate() { + return dueDate; + } + + public void setDueDate(LocalDate dueDate) { + this.dueDate = dueDate; + } +} diff --git a/Answers/40230112013/Library Management System/src/User.java b/Answers/40230112013/Library Management System/src/User.java new file mode 100644 index 0000000..8e2b462 --- /dev/null +++ b/Answers/40230112013/Library Management System/src/User.java @@ -0,0 +1,90 @@ +import java.util.List; +import java.util.Scanner; + +public class User { + private String Name; + private String FamilyName; + private String PhoneNumber; + private String Id; + private String password; + + public User(String name, String surname, String phoneNumber, String userId, String password) { + this.Name = name; + this.FamilyName = surname; + this.PhoneNumber = phoneNumber; + this.password = password; + this.Id = userId; + } + + public String getName() { + return Name; + } + + public String getFamilyName() { + return FamilyName; + } + + public String getPhoneNumber() { + return PhoneNumber; + } + + public String getId() { + return Id; + } + + public String getPassword() { + return password; + } + + public String[] setInformation() { + try (Scanner scanner = new Scanner(System.in)) { + this.Name = scanner.nextLine(); + this.FamilyName = scanner.nextLine(); + this.Id = scanner.nextLine(); + this.password = scanner.nextLine(); + this.PhoneNumber = scanner.nextLine(); + } + String[] values ={Name, FamilyName, Id, password, PhoneNumber}; + return values; + } + + /* @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + User user = (User) obj; + return Name.equals(user.Name) && + FamilyName.equals(user.FamilyName) && + PhoneNumber.equals(user.PhoneNumber) && + password.equals(user.password); + } + + @Override + public int hashCode() { + return Objects.hash(Name, FamilyName, PhoneNumber, password); + }*/ + + public static User userfinder(String n, String p , String j) { + + List me = Library.getuser(); + for (User u : me) { + if (u.getName().equals(n) && u.getPassword().equals(p) && u.getPhoneNumber().equals(j)) { + System.out.println("User found"); + return u; + } + } + System.out.println("User not found"); + return null; + } + public String toString2() { + return "User{" + + "ID='" + Id + '\'' + + ", name='" + Name + '\'' + + ", FamilyName='" + FamilyName + '\'' + + ", PhoneNumber=" + PhoneNumber +'\'' + + '}'; + } +} +