diff --git a/Answers/java project/.idea/.name b/Answers/java project/.idea/.name
new file mode 100644
index 0000000..056975b
--- /dev/null
+++ b/Answers/java project/.idea/.name
@@ -0,0 +1 @@
+Book.java
\ No newline at end of file
diff --git a/Answers/java project/.idea/inspectionProfiles/Project_Default.xml b/Answers/java project/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..12efd36
--- /dev/null
+++ b/Answers/java project/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/.idea/misc.xml b/Answers/java project/.idea/misc.xml
new file mode 100644
index 0000000..862d09b
--- /dev/null
+++ b/Answers/java project/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/.idea/modules.xml b/Answers/java project/.idea/modules.xml
new file mode 100644
index 0000000..2bc8252
--- /dev/null
+++ b/Answers/java project/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/.idea/vcs.xml b/Answers/java project/.idea/vcs.xml
new file mode 100644
index 0000000..64713b8
--- /dev/null
+++ b/Answers/java project/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/.idea/workspace.xml b/Answers/java project/.idea/workspace.xml
new file mode 100644
index 0000000..77c6761
--- /dev/null
+++ b/Answers/java project/.idea/workspace.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 7
+}
+
+
+
+
+
+
+
+
+ {
+ "keyToString": {
+ "Application.CLI.executor": "Run",
+ "Application.MyApp.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "kotlin-language-version-configured": "true"
+ }
+}
+
+
+
+
+ 1715876450758
+
+
+ 1715876450758
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/Admin.java b/Answers/java project/Admin.java
new file mode 100644
index 0000000..1b7ec21
--- /dev/null
+++ b/Answers/java project/Admin.java
@@ -0,0 +1,12 @@
+public class Admin extends User {
+ private String password;
+
+ public Admin(String name, String phoneNumber, String password) {
+ super(name, phoneNumber);
+ this.password = password;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+}
diff --git a/Answers/java project/Book.java b/Answers/java project/Book.java
new file mode 100644
index 0000000..f468ef3
--- /dev/null
+++ b/Answers/java project/Book.java
@@ -0,0 +1,42 @@
+public class Book {
+ private static int idCounter = 1;
+ private int bookID;
+ private String title;
+ private String author;
+ private boolean isAvailable;
+ private String description;
+
+ public Book(String title, String author, String description) {
+ this.bookID = idCounter++;
+ this.title = title;
+ this.author = author;
+ this.isAvailable = true;
+ this.description = description;
+ }
+
+ // Getters and Setters
+ public int getBookID() {
+ return bookID;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public boolean isAvailable() {
+ return isAvailable;
+ }
+
+ public void setAvailable(boolean available) {
+ isAvailable = available;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+ }
+
diff --git a/Answers/java project/CLI.java b/Answers/java project/CLI.java
new file mode 100644
index 0000000..828665b
--- /dev/null
+++ b/Answers/java project/CLI.java
@@ -0,0 +1,76 @@
+import java.util.List;
+import java.util.Scanner;
+
+public class CLI {
+ private static Library library = new Library("City Library", 1000, "9 AM - 5 PM");
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ while (true) {
+ System.out.print("Enter command: ");
+ String command = scanner.nextLine();
+ processCommand(command);
+ }
+ }
+
+ private static void processCommand(String command) {
+ String[] parts = command.split(" ");
+ switch (parts[0]) {
+ case "lib":
+ handleLibraryCommand(parts);
+ break;
+ default:
+ System.out.println("Unknown command");
+ }
+ }
+
+ private static void handleLibraryCommand(String[] parts) {
+ switch (parts[1]) {
+ case "add":
+ if (parts[2].equals("book")) {
+ String title = parts[3];
+ String author = parts[4];
+ String description = parts[5];
+ library.addBook(title, author, description);
+ System.out.println("Book added successfully");
+ } else if (parts[2].equals("member")) {
+ String name = parts[3];
+ String phone = parts[4];
+ String password = parts[5];
+ library.addUser(new Admin(name, phone, password));
+ System.out.println("Member added successfully");
+ }
+ break;
+ case "get":
+ if (parts[2].equals("hrs")) {
+ System.out.println("Library operating hours: " + library.getOperatingHours());
+ } else if (parts[2].equals("available") && parts[3].equals("books")) {
+ List< Book> availableBooks = library.getAvailableBooks();
+ for (Book book : availableBooks) {
+ System.out.println(book.getTitle() + " by " + book.getAuthor());
+ }
+ }
+ break;
+ case "rent":
+ int bookID = Integer.parseInt(parts[2]);
+ int userID = Integer.parseInt(parts[3]);
+ library.rentBook(bookID, userID);
+ System.out.println("Book rented successfully");
+ break;
+ case "return":
+ bookID = Integer.parseInt(parts[2]);
+ library.returnBook(bookID);
+ System.out.println("Book returned successfully");
+ break;
+ case "remove":
+ if (parts[2].equals("member")) {
+ userID = Integer.parseInt(parts[3]);
+ library.removeUser(userID);
+ System.out.println("Member removed successfully");
+ }
+ break;
+ default:
+ System.out.println("Unknown library command");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Answers/java project/Library.java b/Answers/java project/Library.java
new file mode 100644
index 0000000..abd2dca
--- /dev/null
+++ b/Answers/java project/Library.java
@@ -0,0 +1,66 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class Library {
+ private String name;
+ private int capacity;
+ private String operatingHours;
+ private List books;
+ private List users;
+ private List rentals;
+
+ public Library(String name, int capacity, String operatingHours) {
+ this.name = name;
+ this.capacity = capacity;
+ this.operatingHours = operatingHours;
+ this.books = new ArrayList<>();
+ this.users = new ArrayList<>();
+ this.rentals = new ArrayList<>();
+ }
+
+ // Method to add a book
+ public void addBook(String title, String author, String description) {
+ books.add(new Book(title, author, description));
+ }
+
+ public void addUser(User user) {
+ users.add(user);
+ }
+
+ public void removeUser(int userID) {
+ users.removeIf(user -> user.getUserID() == userID);
+ }
+
+ public void rentBook(int bookID, int userID) {
+ Book book = books.stream().filter(b -> b.getBookID() == bookID && b.isAvailable()).findFirst().orElse(null);
+ if (book != null) {
+ User user = users.stream().filter(u -> u.getUserID() == userID && u instanceof NormalUser).findFirst().orElse(null);
+ if (user != null) {
+ book.setAvailable(false);
+ rentals.add(new Rent(book, (NormalUser) user));
+ }
+ }
+ }
+
+
+ public void returnBook(int bookID) {
+ Rent rent = rentals.stream().filter(r -> r.getBook().getBookID() == bookID).findFirst().orElse(null);
+ if (rent != null) {
+ rent.getBook().setAvailable(true);
+ rentals.remove(rent);
+ }
+ }
+
+ public List getAvailableBooks() {
+ List availableBooks = new ArrayList<>();
+ for (Book book : books) {
+ if (book.isAvailable()) {
+ availableBooks.add(book);
+ }
+ }
+ return availableBooks;
+ }
+ public String getOperatingHours() {
+ return operatingHours;
+ }
+}
\ No newline at end of file
diff --git a/Answers/java project/MyApp.java b/Answers/java project/MyApp.java
new file mode 100644
index 0000000..4cb5280
--- /dev/null
+++ b/Answers/java project/MyApp.java
@@ -0,0 +1,5 @@
+public class MyApp {
+ public static void main(String[] args) {
+ CLI.main(args);
+ }
+}
\ No newline at end of file
diff --git a/Answers/java project/NormalUser.java b/Answers/java project/NormalUser.java
new file mode 100644
index 0000000..c3b58cb
--- /dev/null
+++ b/Answers/java project/NormalUser.java
@@ -0,0 +1,15 @@
+import java.util.Date;
+
+ public class NormalUser extends User {
+ private Date registrationDate;
+
+ public NormalUser(String name, String phoneNumber) {
+ super(name, phoneNumber);
+ this.registrationDate = new Date();
+ }
+
+ public Date getRegistrationDate() {
+ return registrationDate;
+ }
+ }
+
diff --git a/Answers/java project/Rent.java b/Answers/java project/Rent.java
new file mode 100644
index 0000000..1e0291f
--- /dev/null
+++ b/Answers/java project/Rent.java
@@ -0,0 +1,32 @@
+import java.util.Date;
+
+public class Rent {
+ private static int idCounter = 1;
+ private int rentalID;
+ private Book book;
+ private NormalUser user;
+ private Date rentalDate;
+
+ public Rent(Book book, NormalUser user) {
+ this.rentalID = idCounter++;
+ this.book = book;
+ this.user = user;
+ this.rentalDate = new Date();
+ }
+
+ public int getRentalID() {
+ return rentalID;
+ }
+
+ public Book getBook() {
+ return book;
+ }
+
+ public NormalUser getUser() {
+ return user;
+ }
+
+ public Date getRentalDate() {
+ return rentalDate;
+ }
+}
\ No newline at end of file
diff --git a/Answers/java project/User.java b/Answers/java project/User.java
new file mode 100644
index 0000000..f0b6fcc
--- /dev/null
+++ b/Answers/java project/User.java
@@ -0,0 +1,26 @@
+public class User {
+ private static int idCounter = 1;
+ private int userID;
+ private String name;
+ private String phoneNumber;
+
+ public User(String name, String phoneNumber) {
+ this.userID = idCounter++;
+ this.name = name;
+ this.phoneNumber = phoneNumber;
+ }
+
+ // Getters and Setters
+ public int getUserID() {
+ return userID;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+ }
+
diff --git a/Answers/java project/out/production/java project/.idea/.gitignore b/Answers/java project/out/production/java project/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/Answers/java project/out/production/java project/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/Answers/java project/out/production/java project/.idea/java project.iml b/Answers/java project/out/production/java project/.idea/java project.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/Answers/java project/out/production/java project/.idea/java project.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/out/production/java project/.idea/misc.xml b/Answers/java project/out/production/java project/.idea/misc.xml
new file mode 100644
index 0000000..862d09b
--- /dev/null
+++ b/Answers/java project/out/production/java project/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/out/production/java project/.idea/modules.xml b/Answers/java project/out/production/java project/.idea/modules.xml
new file mode 100644
index 0000000..2bc8252
--- /dev/null
+++ b/Answers/java project/out/production/java project/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/out/production/java project/.idea/vcs.xml b/Answers/java project/out/production/java project/.idea/vcs.xml
new file mode 100644
index 0000000..6c0b863
--- /dev/null
+++ b/Answers/java project/out/production/java project/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Answers/java project/out/production/java project/Admin.class b/Answers/java project/out/production/java project/Admin.class
new file mode 100644
index 0000000..36c6940
Binary files /dev/null and b/Answers/java project/out/production/java project/Admin.class differ
diff --git a/Answers/java project/out/production/java project/Book.class b/Answers/java project/out/production/java project/Book.class
new file mode 100644
index 0000000..59949c6
Binary files /dev/null and b/Answers/java project/out/production/java project/Book.class differ
diff --git a/Answers/java project/out/production/java project/CLI.class b/Answers/java project/out/production/java project/CLI.class
new file mode 100644
index 0000000..152c597
Binary files /dev/null and b/Answers/java project/out/production/java project/CLI.class differ
diff --git a/Answers/java project/out/production/java project/Library.class b/Answers/java project/out/production/java project/Library.class
new file mode 100644
index 0000000..14288e9
Binary files /dev/null and b/Answers/java project/out/production/java project/Library.class differ
diff --git a/Answers/java project/out/production/java project/MyApp.class b/Answers/java project/out/production/java project/MyApp.class
new file mode 100644
index 0000000..7d53853
Binary files /dev/null and b/Answers/java project/out/production/java project/MyApp.class differ
diff --git a/Answers/java project/out/production/java project/NormalUser.class b/Answers/java project/out/production/java project/NormalUser.class
new file mode 100644
index 0000000..e57c0ec
Binary files /dev/null and b/Answers/java project/out/production/java project/NormalUser.class differ
diff --git a/Answers/java project/out/production/java project/Rent.class b/Answers/java project/out/production/java project/Rent.class
new file mode 100644
index 0000000..a1a225a
Binary files /dev/null and b/Answers/java project/out/production/java project/Rent.class differ
diff --git a/Answers/java project/out/production/java project/User.class b/Answers/java project/out/production/java project/User.class
new file mode 100644
index 0000000..e21ba80
Binary files /dev/null and b/Answers/java project/out/production/java project/User.class differ