diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cdf..9595f6fa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/out/production/s16-Challenge/com/librarysystem/main/LibrarySystem.class b/out/production/s16-Challenge/com/librarysystem/main/LibrarySystem.class new file mode 100644 index 00000000..0cab47a0 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/main/LibrarySystem.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/manager/BookManager.class b/out/production/s16-Challenge/com/librarysystem/manager/BookManager.class new file mode 100644 index 00000000..5d61b863 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/manager/BookManager.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/manager/UserManager.class b/out/production/s16-Challenge/com/librarysystem/manager/UserManager.class new file mode 100644 index 00000000..f1551202 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/manager/UserManager.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Author.class b/out/production/s16-Challenge/com/librarysystem/model/Author.class new file mode 100644 index 00000000..b5cb214a Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Author.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Book.class b/out/production/s16-Challenge/com/librarysystem/model/Book.class new file mode 100644 index 00000000..2e2c56f5 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Book.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Category.class b/out/production/s16-Challenge/com/librarysystem/model/Category.class new file mode 100644 index 00000000..03be2811 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Category.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Invoice.class b/out/production/s16-Challenge/com/librarysystem/model/Invoice.class new file mode 100644 index 00000000..3928b46c Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Invoice.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Library.class b/out/production/s16-Challenge/com/librarysystem/model/Library.class new file mode 100644 index 00000000..1f5c3cd0 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Library.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/Loan.class b/out/production/s16-Challenge/com/librarysystem/model/Loan.class new file mode 100644 index 00000000..1ae5cf21 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/Loan.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/model/User.class b/out/production/s16-Challenge/com/librarysystem/model/User.class new file mode 100644 index 00000000..4261e984 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/model/User.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/service/ILoanable.class b/out/production/s16-Challenge/com/librarysystem/service/ILoanable.class new file mode 100644 index 00000000..2f7a3f51 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/service/ILoanable.class differ diff --git a/out/production/s16-Challenge/com/librarysystem/service/LibraryService.class b/out/production/s16-Challenge/com/librarysystem/service/LibraryService.class new file mode 100644 index 00000000..4b9506c4 Binary files /dev/null and b/out/production/s16-Challenge/com/librarysystem/service/LibraryService.class differ diff --git a/src/Main.java b/src/Main.java deleted file mode 100644 index 3e59c38f..00000000 --- a/src/Main.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/src/com/librarysystem/main/LibrarySystem.java b/src/com/librarysystem/main/LibrarySystem.java new file mode 100644 index 00000000..8be87e23 --- /dev/null +++ b/src/com/librarysystem/main/LibrarySystem.java @@ -0,0 +1,25 @@ +package com.librarysystem.main; + +import com.librarysystem.model.*; +import com.librarysystem.manager.*; +import com.librarysystem.service.*; + +public class LibrarySystem { + public static void main(String[] args) { + Library library = new Library(); + BookManager bookManager = new BookManager(library); + UserManager userManager = new UserManager(library); + LibraryService libraryService = new LibraryService(library); + + Author author = new Author("George Orwell"); + Category category = new Category("Dystopian"); + Book book = new Book("1", "1984", author, category); + bookManager.addBook(book); + + User user = new User("1", "Alice"); + userManager.addUser (user); + + libraryService.loanBook(user, book); + + } +} \ No newline at end of file diff --git a/src/com/librarysystem/manager/BookManager.java b/src/com/librarysystem/manager/BookManager.java new file mode 100644 index 00000000..678b35c2 --- /dev/null +++ b/src/com/librarysystem/manager/BookManager.java @@ -0,0 +1,16 @@ +package com.librarysystem.manager; + +import com.librarysystem.model.Book; +import com.librarysystem.model.Library; + +public class BookManager { + private Library library; + + public BookManager(Library library) { + this.library = library; + } + + public void addBook(Book book) { + library.addBook(book); + } +} \ No newline at end of file diff --git a/src/com/librarysystem/manager/UserManager.java b/src/com/librarysystem/manager/UserManager.java new file mode 100644 index 00000000..11193169 --- /dev/null +++ b/src/com/librarysystem/manager/UserManager.java @@ -0,0 +1,16 @@ +package com.librarysystem.manager; + +import com.librarysystem.model.User; +import com.librarysystem.model.Library; + +public class UserManager { + private Library library; + + public UserManager(Library library) { + this.library = library; + } + + public void addUser (User user) { + library.addUser (user); + } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Author.java b/src/com/librarysystem/model/Author.java new file mode 100644 index 00000000..d6157358 --- /dev/null +++ b/src/com/librarysystem/model/Author.java @@ -0,0 +1,12 @@ +package com.librarysystem.model; + +public class Author { + private String name; + + public Author(String name) { + this.name = name; + } + + // Getters + public String getName() { return name; } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Book.java b/src/com/librarysystem/model/Book.java new file mode 100644 index 00000000..f32ba921 --- /dev/null +++ b/src/com/librarysystem/model/Book.java @@ -0,0 +1,26 @@ +package com.librarysystem.model; + +public class Book { + private String id; + private String title; + private Author author; + private Category category; + private boolean isAvailable; + + public Book(String id, String title, Author author, Category category) { + this.id = id; + this.title = title; + this.author = author; + this.category = category; + this.isAvailable = true; + } + + // Getters and Setters + public String getId() { return id; } + public String getTitle() { return title; } + public Author getAuthor() { return author; } + public Category getCategory() { return category; } + public boolean isAvailable() { return isAvailable; } + public void setAvailable(boolean available) { isAvailable = available; } + public void setTitle(String title) { this.title = title; } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Category.java b/src/com/librarysystem/model/Category.java new file mode 100644 index 00000000..74903663 --- /dev/null +++ b/src/com/librarysystem/model/Category.java @@ -0,0 +1,12 @@ +package com.librarysystem.model; + +public class Category { + private String name; + + public Category(String name) { + this.name = name; + } + + // Getters + public String getName() { return name; } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Invoice.java b/src/com/librarysystem/model/Invoice.java new file mode 100644 index 00000000..3de8e4ab --- /dev/null +++ b/src/com/librarysystem/model/Invoice.java @@ -0,0 +1,16 @@ +package com.librarysystem.model; + +public class Invoice { + private User user; + private Book book; + private double amount; + + public Invoice(User user, Book book, double amount) { + this.user = user; + this.book = book; + this.amount = amount; + } + + // Getters + public double getAmount() { return amount; } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Library.java b/src/com/librarysystem/model/Library.java new file mode 100644 index 00000000..8b91a8c5 --- /dev/null +++ b/src/com/librarysystem/model/Library.java @@ -0,0 +1,56 @@ +package com.librarysystem.model; + +import com.librarysystem.service.ILoanable; + +import java.util.ArrayList; +import java.util.List; + +public class Library implements ILoanable { + private List books; + private List users; + private List loans; + + public Library() { + this.books = new ArrayList<>(); + this.users = new ArrayList<>(); + this.loans = new ArrayList<>(); + } + + public void addBook(Book book) { + books.add(book); + } + + public void addUser (User user) { + users.add(user); + } + + public List getBooks() { + return books; + } + + public List getUsers() { + return users; + } + + @Override + public void loanBook(User user, Book book) { + if (book.isAvailable()) { + book.setAvailable(false); + loans.add(new Loan(user, book)); + System.out.println(user.getName() + " has borrowed " + book.getTitle()); + } else { + System.out.println("The book is not available."); + } + } + + @Override + public void returnBook(User user, Book book) { + if (loans.stream().anyMatch(loan -> loan.getUser ().equals(user) && loan.getBook().equals(book))) { + book.setAvailable(true); + loans.removeIf(loan -> loan.getUser ().equals(user) && loan.getBook().equals(book)); + System.out.println(user.getName() + " has returned " + book.getTitle()); + } else { + System.out.println("This book was not borrowed by the user."); + } + } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/Loan.java b/src/com/librarysystem/model/Loan.java new file mode 100644 index 00000000..4515c5f7 --- /dev/null +++ b/src/com/librarysystem/model/Loan.java @@ -0,0 +1,20 @@ +package com.librarysystem.model; + +import java.util.Date; + +public class Loan { + private User user; + private Book book; + private Date loanDate; + + public Loan(User user, Book book) { + this.user = user; + this.book = book; + this.loanDate = new Date(); + } + + // Getters + public User getUser () { return user; } + public Book getBook() { return book; } + public Date getLoanDate() { return loanDate; } +} \ No newline at end of file diff --git a/src/com/librarysystem/model/User.java b/src/com/librarysystem/model/User.java new file mode 100644 index 00000000..8221f611 --- /dev/null +++ b/src/com/librarysystem/model/User.java @@ -0,0 +1,21 @@ +package com.librarysystem.model; + +import java.util.HashSet; +import java.util.Set; + +public class User { + private String id; + private String name; + private Set borrowedBooks; + + public User(String id, String name) { + this.id = id; + this.name = name; + this.borrowedBooks = new HashSet<>(); + } + + // Getters and Setters + public String getId() { return id; } + public String getName() { return name; } + public Set getBorrowedBooks() { return borrowedBooks; } +} \ No newline at end of file diff --git a/src/com/librarysystem/service/ILoanable.java b/src/com/librarysystem/service/ILoanable.java new file mode 100644 index 00000000..4d4834f1 --- /dev/null +++ b/src/com/librarysystem/service/ILoanable.java @@ -0,0 +1,9 @@ +package com.librarysystem.service; + +import com.librarysystem.model.User; +import com.librarysystem.model.Book; + +public interface ILoanable { + void loanBook(User user, Book book); + void returnBook(User user, Book book); +} \ No newline at end of file diff --git a/src/com/librarysystem/service/LibraryService.java b/src/com/librarysystem/service/LibraryService.java new file mode 100644 index 00000000..9c62931f --- /dev/null +++ b/src/com/librarysystem/service/LibraryService.java @@ -0,0 +1,21 @@ +package com.librarysystem.service; + +import com.librarysystem.model.Library; +import com.librarysystem.model.User; +import com.librarysystem.model.Book; + +public class LibraryService { + private Library library; + + public LibraryService(Library library) { + this.library = library; + } + + public void loanBook(User user, Book book) { + library.loanBook(user, book); + } + + public void returnBook(User user, Book book) { + library.returnBook(user, book); + } +} \ No newline at end of file