From 321c98bd6e259df2ec36940c2346fbcf73b89834 Mon Sep 17 00:00:00 2001 From: Arva Date: Wed, 8 May 2024 19:32:52 +0330 Subject: [PATCH 1/2] Creat classes. --- .../Add Your Projects Here.txt | 0 40230112109/Library/.gitignore | 38 ++++++ 40230112109/Library/.idea/.gitignore | 3 + 40230112109/Library/.idea/.name | 1 + 40230112109/Library/.idea/encodings.xml | 7 + 40230112109/Library/.idea/misc.xml | 14 ++ 40230112109/Library/.idea/uiDesigner.xml | 124 ++++++++++++++++++ 40230112109/Library/.idea/vcs.xml | 6 + 40230112109/Library/pom.xml | 17 +++ .../src/main/java/org/example/Admins.java | 24 ++++ .../src/main/java/org/example/Book.java | 24 ++++ .../src/main/java/org/example/Library.java | 73 +++++++++++ .../src/main/java/org/example/Main.java | 7 + .../main/java/org/example/NormalUsers.java | 24 ++++ .../src/main/java/org/example/Rent.java | 45 +++++++ .../src/main/java/org/example/User.java | 42 ++++++ 16 files changed, 449 insertions(+) rename {Answers => 40230112109}/Add Your Projects Here.txt (100%) create mode 100644 40230112109/Library/.gitignore create mode 100644 40230112109/Library/.idea/.gitignore create mode 100644 40230112109/Library/.idea/.name create mode 100644 40230112109/Library/.idea/encodings.xml create mode 100644 40230112109/Library/.idea/misc.xml create mode 100644 40230112109/Library/.idea/uiDesigner.xml create mode 100644 40230112109/Library/.idea/vcs.xml create mode 100644 40230112109/Library/pom.xml create mode 100644 40230112109/Library/src/main/java/org/example/Admins.java create mode 100644 40230112109/Library/src/main/java/org/example/Book.java create mode 100644 40230112109/Library/src/main/java/org/example/Library.java create mode 100644 40230112109/Library/src/main/java/org/example/Main.java create mode 100644 40230112109/Library/src/main/java/org/example/NormalUsers.java create mode 100644 40230112109/Library/src/main/java/org/example/Rent.java create mode 100644 40230112109/Library/src/main/java/org/example/User.java diff --git a/Answers/Add Your Projects Here.txt b/40230112109/Add Your Projects Here.txt similarity index 100% rename from Answers/Add Your Projects Here.txt rename to 40230112109/Add Your Projects Here.txt diff --git a/40230112109/Library/.gitignore b/40230112109/Library/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/40230112109/Library/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/40230112109/Library/.idea/.gitignore b/40230112109/Library/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/40230112109/Library/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/40230112109/Library/.idea/.name b/40230112109/Library/.idea/.name new file mode 100644 index 0000000..002da1d --- /dev/null +++ b/40230112109/Library/.idea/.name @@ -0,0 +1 @@ +Main.java \ No newline at end of file diff --git a/40230112109/Library/.idea/encodings.xml b/40230112109/Library/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/40230112109/Library/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/40230112109/Library/.idea/misc.xml b/40230112109/Library/.idea/misc.xml new file mode 100644 index 0000000..4258c62 --- /dev/null +++ b/40230112109/Library/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/40230112109/Library/.idea/uiDesigner.xml b/40230112109/Library/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/40230112109/Library/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/40230112109/Library/.idea/vcs.xml b/40230112109/Library/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/40230112109/Library/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/40230112109/Library/pom.xml b/40230112109/Library/pom.xml new file mode 100644 index 0000000..95d6586 --- /dev/null +++ b/40230112109/Library/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + LMS + 1.0-SNAPSHOT + + + 18 + 18 + UTF-8 + + + \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/Admins.java b/40230112109/Library/src/main/java/org/example/Admins.java new file mode 100644 index 0000000..cdc2fa5 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/Admins.java @@ -0,0 +1,24 @@ +package org.example; + +public class Admins extends User{ + // Attributes + private String password; + // Getters & Setters + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + // Constructor + Admins(String name, String uniqueID, String phoneNumber, String password){ + super(name, uniqueID, phoneNumber); + this.password = password; + } + @Override + public void signUp() { + + } +} diff --git a/40230112109/Library/src/main/java/org/example/Book.java b/40230112109/Library/src/main/java/org/example/Book.java new file mode 100644 index 0000000..d6c4b2a --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/Book.java @@ -0,0 +1,24 @@ +package org.example; + +import java.util.UUID; +// Attributes +public class Book { + private UUID bookID; + private String title; + private String author; + private boolean availabilityStatus; + private String description; + // Constructor + Book(String title, String author, boolean availabilityStatus, String description){ + this.bookID = UUID.randomUUID(); + this.title = title; + this.author = author; + this.description = description; + } + // Getters and Setters + public UUID getBookID() { return bookID; } + public String getTitle() { return title; } + public String getAuthor() { return author; } + public boolean isAvailable() { return availabilityStatus; } + public void setAvailabilityStatus(boolean availabilityStatus) { this.availabilityStatus = availabilityStatus; } +} diff --git a/40230112109/Library/src/main/java/org/example/Library.java b/40230112109/Library/src/main/java/org/example/Library.java new file mode 100644 index 0000000..f0c3439 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/Library.java @@ -0,0 +1,73 @@ +package org.example; + +import java.util.ArrayList; +import java.util.List; + +public class Library { + // Attributes + private String libraryName; + private int capacity; + private String operatingHours; + private List books; + private List users; + private List rentals; + // Getters & Setters + + public String getLibraryName() { + return libraryName; + } + + public void setLibraryName(String libraryName) { + this.libraryName = libraryName; + } + + public int getCapacity() { + return capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + + public String getOperatingHours() { + return operatingHours; + } + + public void setOperatingHours(String operatingHours) { + this.operatingHours = operatingHours; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public List getRentals() { + return rentals; + } + + public void setRentals(List rentals) { + this.rentals = rentals; + } + // Constructor + Library(String libraryName, int capacity, String operatingHours){ + this.libraryName = libraryName; + this.capacity = capacity; + this.operatingHours = operatingHours; + this.books = new ArrayList<>(); + this.users = new ArrayList<>(); + this.rentals = new ArrayList<>(); + + } +} diff --git a/40230112109/Library/src/main/java/org/example/Main.java b/40230112109/Library/src/main/java/org/example/Main.java new file mode 100644 index 0000000..407f157 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/Main.java @@ -0,0 +1,7 @@ +package org.example; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/NormalUsers.java b/40230112109/Library/src/main/java/org/example/NormalUsers.java new file mode 100644 index 0000000..0367cb4 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/NormalUsers.java @@ -0,0 +1,24 @@ +package org.example; + +import javax.xml.crypto.Data; +import java.util.Date; + +public class NormalUsers extends User{ + // Attributes + private Date registrationDate; + // Getters & Setters + public Date getRegistrationDate() { + return registrationDate; + } + // Constructor + public void setRegistrationDate(Date registrationDate) { + this.registrationDate = registrationDate; + } + + + + NormalUsers(String name, String uniqueID, String phoneNumber, Date registrationDate) { + super(name, uniqueID, phoneNumber); + this.registrationDate = registrationDate; + } +} diff --git a/40230112109/Library/src/main/java/org/example/Rent.java b/40230112109/Library/src/main/java/org/example/Rent.java new file mode 100644 index 0000000..8dcd354 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/Rent.java @@ -0,0 +1,45 @@ +package org.example; + +import javax.xml.crypto.Data; +import java.util.Date; + +public class Rent { + // Attributes + private Book book; + private NormalUsers normalUsersormal; + private String rentalID; + private Date rentalDate; + // Getters & Setters + public Book getBook() { + return book; + } + + public void setBook(Book book) { + this.book = book; + } + + public NormalUsers getNormalUsersormal() { + return normalUsersormal; + } + + public void setNormalUsersormal(NormalUsers normalUsersormal) { + this.normalUsersormal = normalUsersormal; + } + + public String getRentalID() { + return rentalID; + } + + public void setRentalID(String rentalID) { + this.rentalID = rentalID; + } + + public Date getRentalDate() { + return rentalDate; + } + + public void setRentalDate(Date rentalDate) { + this.rentalDate = rentalDate; + } + // Constructor +} diff --git a/40230112109/Library/src/main/java/org/example/User.java b/40230112109/Library/src/main/java/org/example/User.java new file mode 100644 index 0000000..8745afb --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/User.java @@ -0,0 +1,42 @@ +package org.example; + +public abstract class User { + private String name; + private String uniqueID; + private String phoneNumber; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUniqueID() { + return uniqueID; + } + + public void setUniqueID(String uniqueID) { + this.uniqueID = uniqueID; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + User(String name, String uniqueID, String phoneNumber){ + this.name = name; + this.uniqueID = uniqueID; + this.phoneNumber = phoneNumber; + } + + void signUp() { + + } + +} From 193ffd53012a14196bd23f97a1554a7fc8dd7f7e Mon Sep 17 00:00:00 2001 From: Arva Date: Fri, 17 May 2024 00:05:11 +0330 Subject: [PATCH 2/2] Done. --- 40230112109/LMS/.idea/workspace.xml | 92 ++++++++++++++ .../inspectionProfiles/Project_Default.xml | 7 + .../src/main/java/org/example/Admins.java | 5 +- .../src/main/java/org/example/Book.java | 61 +++++++-- .../src/main/java/org/example/Library.java | 120 +++++++++++++++--- .../src/main/java/org/example/LibraryCLI.java | 113 +++++++++++++++++ .../src/main/java/org/example/Main.java | 7 - .../src/main/java/org/example/MyApp.java | 14 ++ .../main/java/org/example/NormalUsers.java | 10 +- .../src/main/java/org/example/Rent.java | 31 +++-- .../src/main/java/org/example/User.java | 37 +++--- 11 files changed, 428 insertions(+), 69 deletions(-) create mode 100644 40230112109/LMS/.idea/workspace.xml create mode 100644 40230112109/Library/.idea/inspectionProfiles/Project_Default.xml create mode 100644 40230112109/Library/src/main/java/org/example/LibraryCLI.java delete mode 100644 40230112109/Library/src/main/java/org/example/Main.java create mode 100644 40230112109/Library/src/main/java/org/example/MyApp.java diff --git a/40230112109/LMS/.idea/workspace.xml b/40230112109/LMS/.idea/workspace.xml new file mode 100644 index 0000000..eaad679 --- /dev/null +++ b/40230112109/LMS/.idea/workspace.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + { + "associatedIndex": 4 +} + + + + + + + + + + + + + + + + + + + + + + + + + + + 1713872559761 + + + + \ No newline at end of file diff --git a/40230112109/Library/.idea/inspectionProfiles/Project_Default.xml b/40230112109/Library/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c43d165 --- /dev/null +++ b/40230112109/Library/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/Admins.java b/40230112109/Library/src/main/java/org/example/Admins.java index cdc2fa5..a02ff00 100644 --- a/40230112109/Library/src/main/java/org/example/Admins.java +++ b/40230112109/Library/src/main/java/org/example/Admins.java @@ -1,5 +1,7 @@ package org.example; +import java.util.Date; + public class Admins extends User{ // Attributes private String password; @@ -17,8 +19,9 @@ public void setPassword(String password) { super(name, uniqueID, phoneNumber); this.password = password; } + @Override - public void signUp() { + public void register(Date registrationDate) { } } diff --git a/40230112109/Library/src/main/java/org/example/Book.java b/40230112109/Library/src/main/java/org/example/Book.java index d6c4b2a..d3587ec 100644 --- a/40230112109/Library/src/main/java/org/example/Book.java +++ b/40230112109/Library/src/main/java/org/example/Book.java @@ -1,24 +1,65 @@ package org.example; import java.util.UUID; -// Attributes +//***** Attributes *****// public class Book { - private UUID bookID; + private String bookID; private String title; private String author; - private boolean availabilityStatus; private String description; + private boolean availability; + // Constructor - Book(String title, String author, boolean availabilityStatus, String description){ - this.bookID = UUID.randomUUID(); + Book(String title, String author, String description){ this.title = title; this.author = author; this.description = description; + this.bookID = generateUniqueId(); + this.availability = true; } // Getters and Setters - public UUID getBookID() { return bookID; } - public String getTitle() { return title; } - public String getAuthor() { return author; } - public boolean isAvailable() { return availabilityStatus; } - public void setAvailabilityStatus(boolean availabilityStatus) { this.availabilityStatus = availabilityStatus; } + + public String getBookID() { + return bookID; + } + + public void setBookID(String bookID) { + this.bookID = bookID; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isAvailability() { + return availability; + } + + public void setAvailability(boolean availability) { + this.availability = availability; + } + + public static String generateUniqueId(){ + return UUID.randomUUID().toString(); + } } diff --git a/40230112109/Library/src/main/java/org/example/Library.java b/40230112109/Library/src/main/java/org/example/Library.java index f0c3439..bab01ea 100644 --- a/40230112109/Library/src/main/java/org/example/Library.java +++ b/40230112109/Library/src/main/java/org/example/Library.java @@ -1,18 +1,28 @@ package org.example; - -import java.util.ArrayList; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; public class Library { // Attributes private String libraryName; private int capacity; private String operatingHours; - private List books; + // String = bookId + private Map booksMap; private List users; private List rentals; - // Getters & Setters + //***** Constructor *****// + Library(String libraryName, int capacity, String operatingHours) { + this.libraryName = libraryName; + this.capacity = capacity; + this.operatingHours = operatingHours; + this.booksMap = new HashMap<>(); + this.users = new ArrayList<>(); + this.rentals = new ArrayList<>(); + } + + //***** Getters & Setters *****// public String getLibraryName() { return libraryName; } @@ -37,12 +47,12 @@ public void setOperatingHours(String operatingHours) { this.operatingHours = operatingHours; } - public List getBooks() { - return books; + public Map getBooksMap() { + return booksMap; } - public void setBooks(List books) { - this.books = books; + public void setBooksMap(Map booksMap) { + this.booksMap = booksMap; } public List getUsers() { @@ -60,14 +70,90 @@ public List getRentals() { public void setRentals(List rentals) { this.rentals = rentals; } - // Constructor - Library(String libraryName, int capacity, String operatingHours){ - this.libraryName = libraryName; - this.capacity = capacity; - this.operatingHours = operatingHours; - this.books = new ArrayList<>(); - this.users = new ArrayList<>(); - this.rentals = new ArrayList<>(); + //***** Methods *****// + public void addBook(Book book) { + // Ensure book ID is unique + String bookId = Book.generateUniqueId(); + book.setBookID(bookId); + booksMap.put(bookId, book); + // Check library capacity + if (users.size() >= capacity) { + System.out.println("Library is full."); + return; + } + booksMap.put(bookId, book); + } + + // To find book. + public Book findBookById(String id) { + boolean result = false; + for (int i = 0; i < this.booksMap.size(); i++) { + if (this.booksMap.get(i).equals(id)) { + result = true; + } + } + if (!result) { + System.out.println("This book is not avalibale!"); + } + return booksMap.get(id); + } + + // To add a user by admin. + public void addUser(User user) { + // Check if the user is an admin trying to add another admin + if (user instanceof Admins && users.stream().anyMatch(u -> u instanceof Admins)) { + System.out.println("Only one admin can exist."); + return; + } + users.add(user); + } + + // To find user. + public User findUserById(String id) { + return users.stream().filter(u -> u.getUniqueID().equals(id)).findFirst().orElse(null); + } + + // To show all book. + public List getAvailableBooks() { + return booksMap.values().stream().filter(Book::isAvailability).collect(Collectors.toList()); + } + + public void returnBook(String bookId) { + Book book = booksMap.get(bookId); + if (book != null) { + Optional optionalRental = rentals.stream() + .filter(r -> r.getBook().equals(book)) + .findFirst(); + if (optionalRental.isPresent()) { + Rent rental = optionalRental.get(); + rental.setReturned(true); + book.setAvailability(true); + } + } + } + + private String generateUniqueId() { + return UUID.randomUUID().toString(); + } + + public User findUserByNameOrId(String nameOrId) { + return users.stream() + .filter(u -> u.getUniqueID().equals(nameOrId) || u.getUserName().equalsIgnoreCase(nameOrId)) + .findFirst() + .orElse(null); + } + + public void rentBook(String bookId, User user) { + Book book = booksMap.get(bookId); + if (book != null && book.isAvailability()) { + // Assuming there's a way to mark a book as unavailable + book.setAvailability(false); + // Create a new rental record + rentals.add(new Rent(book, (NormalUsers) user, new Date())); + System.out.println("Book rented successfully."); + } else { + System.out.println("The book is not available or not found."); + } } } diff --git a/40230112109/Library/src/main/java/org/example/LibraryCLI.java b/40230112109/Library/src/main/java/org/example/LibraryCLI.java new file mode 100644 index 0000000..f624136 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/LibraryCLI.java @@ -0,0 +1,113 @@ +package org.example; + +import java.util.List; +import java.util.Scanner; +public class LibraryCLI { + private Library library; + + public LibraryCLI(Library library) { + this.library = library; + } + + public void run() { + Scanner scanner = new Scanner(System.in); + while (true) { + System.out.print("\nEnter command:(Write \"help\" to see all commands.) "); + String command = scanner.nextLine(); + String[] parts = command.split(" "); + + if (parts.length == 0) { + continue; // Skip empty lines + } + + String action = parts[0].toLowerCase(); + + if ("help".equalsIgnoreCase(action)) { + printHelpCommands(); + continue; + } + + if ("add book".equalsIgnoreCase(action)) { + if (parts.length != 4) { + System.out.println("Usage: lib add book <author> [<description>]"); + continue; + } + String title = parts[1]; + String author = parts[2]; + String description = parts.length > 3 ? parts[3] : ""; + library.addBook(new Book(title, author, description)); + } else if ("get hrs".equalsIgnoreCase(action)) { + System.out.println("Library operating hours are 9 AM - 5 PM."); + } else if ("rent".equalsIgnoreCase(action)) { + if (parts.length != 2) { + System.out.println("Usage: lib rent <bookTitle>"); + continue; + } + String bookTitle = parts[1]; + Book book = library.findBookById(bookTitle); + if (book != null && book.isAvailability()) { + // Assuming there's a way to find the user by name or ID + User user = library.findUserByNameOrId(parts[2]); // Placeholder method + if (user != null) { + library.rentBook(String.valueOf(book), user); + } else { + System.out.println("User not found."); + } + } else { + System.out.println("Book not available or not found."); + } + } else if ("add member".equalsIgnoreCase(action)) { + if (parts.length != 3) { + System.out.println("Usage: lib add member <id> <password>"); + continue; + } + String id = parts[1]; + String password = parts[2]; + library.addUser(new Admins("Admin", id, "", password)); // Simplified for demonstration + } else if ("rent for member".equalsIgnoreCase(action)) { + if (parts.length != 4) { + System.out.println("Usage: lib rent <bookTitle> <memberName> <memberID>"); + continue; + } + String bookTitle = parts[1]; + String memberName = parts[2]; + String memberID = parts[3]; + // Similar to "rent" but finds the member by name or ID + } else if ("get available books".equalsIgnoreCase(action)) { + List<Book> availableBooks = library.getAvailableBooks(); + System.out.println("Available books:"); + for (Book book : availableBooks) { + System.out.println(book.getTitle()); + } + } else if ("remove member".equalsIgnoreCase(action)) { + if (parts.length != 2) { + System.out.println("Usage: lib remove member <id>"); + continue; + } + String id = parts[1]; + // Find and remove the member + } else if ("return".equalsIgnoreCase(action)) { + if (parts.length != 2) { + System.out.println("Usage: lib return <bookTitle>"); + continue; + } + String bookTitle = parts[1]; + library.returnBook(bookTitle); + } else { + System.out.println("Unknown command."); + } + } + } + private void printHelpCommands() { + System.out.println("\nAvailable Commands:"); + System.out.println("1. Add a book: lib add book <title> <author> [<description>]"); + System.out.println("2. Get library hours: lib get hrs"); + System.out.println("3. Rent a book: lib rent <bookTitle>"); + System.out.println("4. Add a member: lib add member <id> <password>"); + System.out.println("5. Rent a book for a member: lib rent <bookTitle> <memberName> <memberID>"); + System.out.println("6. Get available books: lib get available books"); + System.out.println("7. Remove a member: lib remove member <id>"); + System.out.println("8. Return a book: lib return <bookTitle>"); + System.out.println("Type 'help' anytime for this list of commands."); + } +} \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/Main.java b/40230112109/Library/src/main/java/org/example/Main.java deleted file mode 100644 index 407f157..0000000 --- a/40230112109/Library/src/main/java/org/example/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.example; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/MyApp.java b/40230112109/Library/src/main/java/org/example/MyApp.java new file mode 100644 index 0000000..72928d3 --- /dev/null +++ b/40230112109/Library/src/main/java/org/example/MyApp.java @@ -0,0 +1,14 @@ +package org.example; + +public class MyApp { + public static void main(String[] args) { + System.out.print("Hi! Welcome to Arva's library♥"); + Library library = new Library("Example Library", 100, "9 AM - 5 PM"); + + // Create an instance of LibraryCLI + LibraryCLI cli = new LibraryCLI(library); + + // Start the interactive session + cli.run(); + } +} \ No newline at end of file diff --git a/40230112109/Library/src/main/java/org/example/NormalUsers.java b/40230112109/Library/src/main/java/org/example/NormalUsers.java index 0367cb4..447f9e6 100644 --- a/40230112109/Library/src/main/java/org/example/NormalUsers.java +++ b/40230112109/Library/src/main/java/org/example/NormalUsers.java @@ -10,15 +10,17 @@ public class NormalUsers extends User{ public Date getRegistrationDate() { return registrationDate; } - // Constructor public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } - - - + // Constructor NormalUsers(String name, String uniqueID, String phoneNumber, Date registrationDate) { super(name, uniqueID, phoneNumber); this.registrationDate = registrationDate; } + + @Override + public void register(Date registrationDate) { + this.registrationDate = registrationDate; + } } diff --git a/40230112109/Library/src/main/java/org/example/Rent.java b/40230112109/Library/src/main/java/org/example/Rent.java index 8dcd354..2d679a4 100644 --- a/40230112109/Library/src/main/java/org/example/Rent.java +++ b/40230112109/Library/src/main/java/org/example/Rent.java @@ -6,10 +6,11 @@ public class Rent { // Attributes private Book book; - private NormalUsers normalUsersormal; - private String rentalID; + private NormalUsers normalUser; + private boolean returned; private Date rentalDate; // Getters & Setters + public Book getBook() { return book; } @@ -18,22 +19,22 @@ public void setBook(Book book) { this.book = book; } - public NormalUsers getNormalUsersormal() { - return normalUsersormal; + public NormalUsers getNormalUser() { + return normalUser; } - public void setNormalUsersormal(NormalUsers normalUsersormal) { - this.normalUsersormal = normalUsersormal; + public void setNormalUser(NormalUsers normalUser) { + this.normalUser = normalUser; } - public String getRentalID() { - return rentalID; + public boolean isReturned() { + return returned; } - public void setRentalID(String rentalID) { - this.rentalID = rentalID; + public void setReturned(boolean returned) { + this.returned = returned; } - + //***** Methods *****// public Date getRentalDate() { return rentalDate; } @@ -41,5 +42,13 @@ public Date getRentalDate() { public void setRentalDate(Date rentalDate) { this.rentalDate = rentalDate; } + // Constructor + + public Rent(Book book, NormalUsers normalUser, Date rentalDate) { + this.book = book; + this.normalUser = normalUser; + this.returned = false; + this.rentalDate = rentalDate; + } } diff --git a/40230112109/Library/src/main/java/org/example/User.java b/40230112109/Library/src/main/java/org/example/User.java index 8745afb..f91fbea 100644 --- a/40230112109/Library/src/main/java/org/example/User.java +++ b/40230112109/Library/src/main/java/org/example/User.java @@ -1,16 +1,24 @@ package org.example; -public abstract class User { - private String name; - private String uniqueID; - private String phoneNumber; +import java.util.Date; - public String getName() { - return name; +public abstract class User { + protected String userName; + protected String uniqueID; + protected String phoneNumber; + //***** Constructor *****// + User(String name, String uniqueID, String phoneNumber){ + this.userName = name; + this.uniqueID = uniqueID; + this.phoneNumber = phoneNumber; + } + //***** Getters & Setters *****// + public String getUserName() { + return userName; } - public void setName(String name) { - this.name = name; + public void setUserName(String userName) { + this.userName = userName; } public String getUniqueID() { @@ -28,15 +36,6 @@ public String getPhoneNumber() { public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } - - User(String name, String uniqueID, String phoneNumber){ - this.name = name; - this.uniqueID = uniqueID; - this.phoneNumber = phoneNumber; - } - - void signUp() { - - } - + //***** Methods *****// + public abstract void register(Date registrationDate); }