diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cdf..de8c3387 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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/README.md b/README.md index cf4d4e1c..34a2b98f 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Proje sayımız ilerledikçe proje yönetimimizi kolaylaştırmak adına projele ### Hedeflerimiz: -### Library System +### library.Library System * ![](challenge1.png) * Bir kütüphane sistemi modelimiz mevcut. diff --git a/out/production/s16-Challenge/Main.class b/out/production/s16-Challenge/Main.class new file mode 100644 index 00000000..23de7a26 Binary files /dev/null and b/out/production/s16-Challenge/Main.class differ diff --git a/out/production/s16-Challenge/Shared/CustomDate.class b/out/production/s16-Challenge/Shared/CustomDate.class new file mode 100644 index 00000000..78dc6f70 Binary files /dev/null and b/out/production/s16-Challenge/Shared/CustomDate.class differ diff --git a/out/production/s16-Challenge/book/Book.class b/out/production/s16-Challenge/book/Book.class new file mode 100644 index 00000000..b8f233fe Binary files /dev/null and b/out/production/s16-Challenge/book/Book.class differ diff --git a/out/production/s16-Challenge/book/BookEdition.class b/out/production/s16-Challenge/book/BookEdition.class new file mode 100644 index 00000000..d1532e44 Binary files /dev/null and b/out/production/s16-Challenge/book/BookEdition.class differ diff --git a/out/production/s16-Challenge/book/BookStatus.class b/out/production/s16-Challenge/book/BookStatus.class new file mode 100644 index 00000000..5533a508 Binary files /dev/null and b/out/production/s16-Challenge/book/BookStatus.class differ diff --git a/out/production/s16-Challenge/book/GenreEnum.class b/out/production/s16-Challenge/book/GenreEnum.class new file mode 100644 index 00000000..c6003bda Binary files /dev/null and b/out/production/s16-Challenge/book/GenreEnum.class differ diff --git a/out/production/s16-Challenge/book/bookSubClasses/Journals.class b/out/production/s16-Challenge/book/bookSubClasses/Journals.class new file mode 100644 index 00000000..afc1d2a9 Binary files /dev/null and b/out/production/s16-Challenge/book/bookSubClasses/Journals.class differ diff --git a/out/production/s16-Challenge/book/bookSubClasses/Magazines.class b/out/production/s16-Challenge/book/bookSubClasses/Magazines.class new file mode 100644 index 00000000..31b1caf9 Binary files /dev/null and b/out/production/s16-Challenge/book/bookSubClasses/Magazines.class differ diff --git a/out/production/s16-Challenge/book/bookSubClasses/StudyBooks.class b/out/production/s16-Challenge/book/bookSubClasses/StudyBooks.class new file mode 100644 index 00000000..266ef66e Binary files /dev/null and b/out/production/s16-Challenge/book/bookSubClasses/StudyBooks.class differ diff --git a/out/production/s16-Challenge/description.puml b/out/production/s16-Challenge/description.puml new file mode 100644 index 00000000..6f8cae07 --- /dev/null +++ b/out/production/s16-Challenge/description.puml @@ -0,0 +1,117 @@ +@startuml +package person { + + class Person { + - name: String + # whoyouare(): String + } + + class Reader { + - member_record: MemberRecord + --- + + setMember_record(memberRecord: MemberRecord): void + + getMember_record(): MemberRecord + # whoyouare(): String + } + + class Author { + - books: Set + + show_book(): Set + + setBooks(books: Set): void + + new_book(book: Book): boolean + + whoyouare(): String + } + + class Librarian { + - password: String + - library: Library + + Librarian(name: String, password: String, library: Library) + + getLibrary(): Library + + createRecord(reader: Reader, memberRecord: MemberRecord): boolean + + addReaderToLibrary(reader: Reader): boolean + + giveBackBook(bookId: long): boolean + + whoyouare(): String + } + + class MemberRecord { + - member_id: long + - library: Library + - reader: Reader + - type: membershipType + - date_of_membership: CustomDate + - lendedBooks: Set + - MAX_LENDED_BOOKS: int + - dept: double + + MemberRecord() + + MemberRecord(member_id: long, type: membershipType, reader: Reader, library: Library) + + getDept(): double + + getLendedBooks(): Set + + getLibrary(): Library + + setLibrary(library: Library): void + + addBookToLendedBooks(book: Book): boolean + + returnBook(id: long): boolean + + toString(): String + } + + Person <|-- Author : Inherits + Person <|-- Reader : Inherits + Person <|-- Librarian : Inherits + Reader --> MemberRecord : Has a + MemberRecord --> Library : Uses +} + +package book { + class Book { + + getPrice(): double + + getName(): String + + setStatus(status: BookStatus): void + + setOwner(owner: MemberRecord): void + + get_author(): Author + + getGenre(): GenreEnum + + lendBook(record: MemberRecord): void + + getBookId(): long + } + + class BookStatus { + <> + + AVAILABLE + + ON_HOLD + + LENT_OUT + } + + class GenreEnum { + <> + + FICTION + + NON_FICTION + + SCI_FI + + BIOGRAPHY + + FANTASY + } +} + +package library { + class Library { + - books: Map + - readers: Map + + Library() + + Library(books: Map, readers: Map) + + get_book(): Map + + get_book(id: long): Book + + get_book(name: String): Book + + get_book(author: Author): Set + + deleteBook(id: long): boolean + + getBooksByGenre(genre: GenreEnum): List + + get_readers(): Map + + searchForReader(name: String): Reader + + new_book(book: Book): boolean + + addReader(reader: Reader): boolean + + lendBook(bookId: long, readerName: String): boolean + + toString(): String + } +} + +Author --> Book : Has a Set of +Library --> Book : Contains +Library --> Reader : Contains +Library --> MemberRecord : Uses +@enduml diff --git a/out/production/s16-Challenge/library/Library.class b/out/production/s16-Challenge/library/Library.class new file mode 100644 index 00000000..3c52efd7 Binary files /dev/null and b/out/production/s16-Challenge/library/Library.class differ diff --git a/out/production/s16-Challenge/person/Author.class b/out/production/s16-Challenge/person/Author.class new file mode 100644 index 00000000..90d7cbaa Binary files /dev/null and b/out/production/s16-Challenge/person/Author.class differ diff --git a/out/production/s16-Challenge/person/Librarian.class b/out/production/s16-Challenge/person/Librarian.class new file mode 100644 index 00000000..97bc1aef Binary files /dev/null and b/out/production/s16-Challenge/person/Librarian.class differ diff --git a/out/production/s16-Challenge/person/Person.class b/out/production/s16-Challenge/person/Person.class new file mode 100644 index 00000000..e4741c18 Binary files /dev/null and b/out/production/s16-Challenge/person/Person.class differ diff --git a/out/production/s16-Challenge/person/reader/MemberRecord.class b/out/production/s16-Challenge/person/reader/MemberRecord.class new file mode 100644 index 00000000..9054803e Binary files /dev/null and b/out/production/s16-Challenge/person/reader/MemberRecord.class differ diff --git a/out/production/s16-Challenge/person/reader/Reader.class b/out/production/s16-Challenge/person/reader/Reader.class new file mode 100644 index 00000000..b4d6af0e Binary files /dev/null and b/out/production/s16-Challenge/person/reader/Reader.class differ diff --git a/out/production/s16-Challenge/person/reader/membershipType.class b/out/production/s16-Challenge/person/reader/membershipType.class new file mode 100644 index 00000000..ca8037ec Binary files /dev/null and b/out/production/s16-Challenge/person/reader/membershipType.class differ diff --git a/src/Main.java b/src/Main.java index 3e59c38f..12245f31 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,50 @@ +import Shared.CustomDate; +import book.Book; +import book.BookEdition; +import book.GenreEnum; +import library.Library; +import person.Author; +import person.Librarian; + +import person.reader.MemberRecord; +import person.reader.Reader; +import person.reader.membershipType; + + public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + Library library = new Library(); + Author author = new Author("Ridvan"); + Reader mete = new Reader("mete"); + MemberRecord meteRecord = new MemberRecord(1, membershipType.PREMIUM,mete,library); + + Librarian librarian = new Librarian("Ridvan","bekar5561",library); + librarian.addReaderToLibrary(mete); + librarian.createRecord(mete,meteRecord); + + Book book1 = new Book(1,author,"Narnia", "Cadı, kapı, aslan 1",20.00, BookEdition.FIRST_EDITION, new CustomDate(1,1,1998),GenreEnum.ADVENTURE); + Book book2 = new Book(2,author,"Narnia 1","Cadı, kapı, aslan 2",18.00, BookEdition.FIRST_EDITION, new CustomDate(1,1,1998),GenreEnum.ADVENTURE); + Book book3 = new Book(3,author,"Narnia 2","Cadı, kapı, aslan 3",16.00, BookEdition.FIRST_EDITION, new CustomDate(1,1,1998),GenreEnum.ADVENTURE); + Book book4 = new Book(4,author,"Atatürk","Ülke nasıl kurulur?",300.00, BookEdition.HARDCOVER_EDITION, new CustomDate(1,1,1881),GenreEnum.HISTORICAL); + Book book5 = new Book(5,author,"Atatürk","Ülke nasıl kurulur?",300.00, BookEdition.HARDCOVER_EDITION, new CustomDate(1,1,1881),GenreEnum.HISTORICAL); + + library.new_book(book1); + library.new_book(book2); + library.new_book(book3); + library.new_book(book4); + library.new_book(book5); + + System.out.println("menekşe"); + library.get_book(1); + System.out.println(library.get_book(2)); + System.out.println("menekşe"); + library.lendBook(3,"mete"); + library.lendBook(1,"mete"); + library.lendBook(2,"mete"); + librarian.giveBackBook(1); + System.out.println(meteRecord.getDept()); + + Book istegim = library.get_book(2); + library.lendBook(3,"mete"); } } \ No newline at end of file diff --git a/src/Shared/CustomDate.java b/src/Shared/CustomDate.java new file mode 100644 index 00000000..78870032 --- /dev/null +++ b/src/Shared/CustomDate.java @@ -0,0 +1,113 @@ +package Shared; + +import java.time.LocalDate; + +public class CustomDate { + private int day; + private int month; + private int year; + + // Constructor + public CustomDate(int day, int month, int year) { + if (isValidDate(day, month, year)) { + this.day = day; + this.month = month; + this.year = year; + } else { + throw new IllegalArgumentException("Invalid date"); + } + } + + public static CustomDate now(){ + LocalDate currentDate = LocalDate.now(); + int year = currentDate.getYear(); + int month = currentDate.getMonthValue(); + int day = currentDate.getDayOfMonth(); + return new CustomDate(day,month,year); + } + + // Getters + public int getDay() { + return day; + } + + public int getMonth() { + return month; + } + + public int getYear() { + return year; + } + + // Setters with validation + public void setDay(int day) { + if (isValidDate(day, this.month, this.year)) { + this.day = day; + } else { + throw new IllegalArgumentException("Invalid day"); + } + } + + public void setMonth(int month) { + if (isValidDate(this.day, month, this.year)) { + this.month = month; + } else { + throw new IllegalArgumentException("Invalid month"); + } + } + + public void setYear(int year) { + if (isValidDate(this.day, this.month, year)) { + this.year = year; + } else { + throw new IllegalArgumentException("Invalid year"); + } + } + + // Method to check if the date is valid + private boolean isValidDate(int day, int month, int year) { + if (year < 0) { + return false; + } + if (month < 1 || month > 12) { + return false; + } + int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; + + // Check for leap year + if (isLeapYear(year)) { + daysInMonth[1] = 29; // February has 29 days in leap year + } + + return day > 0 && day <= daysInMonth[month - 1]; + } + + // Leap year checker + private boolean isLeapYear(int year) { + return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); + } + + // Method to display the date as a string + @Override + public String toString() { + return String.format("%02d/%02d/%04d", day, month, year); + } + + // Compare two dates (returns true if this date is earlier than another) + public boolean isEarlierThan(CustomDate other) { + if (this.year < other.year) { + return true; + } else if (this.year == other.year) { + if (this.month < other.month) { + return true; + } else if (this.month == other.month) { + return this.day < other.day; + } + } + return false; + } + // Check if two dates are equal + public boolean equals(CustomDate other) { + return this.day == other.day && this.month == other.month && this.year == other.year; + } +} diff --git a/src/book/Book.java b/src/book/Book.java new file mode 100644 index 00000000..ac52b9e6 --- /dev/null +++ b/src/book/Book.java @@ -0,0 +1,178 @@ +package book; + +import Shared.CustomDate; +import person.Author; +import person.Person; +import person.reader.MemberRecord; +import person.reader.Reader; + +import java.time.LocalDate; +import java.util.Objects; + +public class Book implements Comparable{ + private long bookId; + private Author author; + private MemberRecord owner; + private String name; + private String title; + private GenreEnum genre; + private double price; + private BookStatus status; + private BookEdition edition; + private CustomDate dateofpurches; + private CustomDate dateoflending; + + public Book(long bookId, Author author, String name, String title, double price, BookEdition edition, CustomDate dateofpurches, GenreEnum genre) { + this.bookId = bookId; + this.author = author; + this.name = name; + this.genre = genre; + this.title = title; + this.price = price; + this.status = BookStatus.AVAILABLE; + this.edition = edition; + this.dateofpurches = dateofpurches; + } + + public Book lendBook(MemberRecord owner){ + this.owner = owner; + setStatus(BookStatus.ON_HOLD); + setDateoflending(CustomDate.now()); + return this; + } + + public Book giveBackBook(){ + setDateoflending(null); + this.owner = null; + setStatus(BookStatus.AVAILABLE); + return this; + } + + public GenreEnum getGenre() { + return genre; + } + + public void setGenre(GenreEnum genre) { + this.genre = genre; + } + + public long getBookId() { + return bookId; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public void setBookId(long bookId) { + this.bookId = bookId; + } + + public void setAuthor(Author author) { + this.author = author; + } + + public void setOwner(MemberRecord owner) { + this.owner = owner; + } + + public void setName(String name) { + this.name = name; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setStatus(BookStatus status) { + this.status = status; + } + + public void setEdition(BookEdition edition) { + this.edition = edition; + } + + public BookStatus getStatus() { + return status; + } + + public void setDateofpurches(CustomDate dateofpurches) { + this.dateofpurches = dateofpurches; + } + + public String getName() { + return name; + } + + public String get_title() { + return title; + } + + public Author get_author() { + return author; + } + + public void change_owner(MemberRecord owner) { + this.owner = owner; + } + + public MemberRecord get_owner() { + return owner; + } + + public CustomDate getDateoflending() { + return dateoflending; + } + + public void setDateoflending(CustomDate dateoflending) { + this.dateoflending = dateoflending; + } + + public String display() { + return "Book{" + + "bookId=" + bookId + + ", author=" + author + + ", name='" + name + '\'' + + ", title='" + title + '\'' + + ", price=" + price + + ", status=" + status + + ", edition=" + edition + + ", dateofpurches=" + dateofpurches + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Book book = (Book) o; + return bookId == book.bookId && Objects.equals(name, book.name) && Objects.equals(title, book.title); + } + + + @Override + public int hashCode() { + return Objects.hash(bookId, name, title); + } + + @Override + public int compareTo(Object o) { + Book book = (Book) o; + if(book.equals(this))return 0; + return this.dateoflending.isEarlierThan(book.getDateoflending()) ? 1 : -1; + } + + @Override + public String toString() { + return "Book{" + + "bookId=" + bookId + + ", name='" + name + '\'' + + ", author=" + author + + ", title='" + title + '\'' + + '}'; + } +} diff --git a/src/book/BookEdition.java b/src/book/BookEdition.java new file mode 100644 index 00000000..1d1a709f --- /dev/null +++ b/src/book/BookEdition.java @@ -0,0 +1,11 @@ +package book; + +public enum BookEdition { + FIRST_EDITION, + REVISED_EDITION, + EXPANDED_EDITION, + SPECIAL_EDITION, + POCKET_EDITION, + HARDCOVER_EDITION, + PAPERBACK_EDITION +} diff --git a/src/book/BookStatus.java b/src/book/BookStatus.java new file mode 100644 index 00000000..14094fc3 --- /dev/null +++ b/src/book/BookStatus.java @@ -0,0 +1,11 @@ +package book; + +public enum BookStatus { + AVAILABLE, + SOLD, + CHECKED_OUT, + RESERVED, + ON_HOLD, + LOST, + DAMAGED +} diff --git a/src/book/GenreEnum.java b/src/book/GenreEnum.java new file mode 100644 index 00000000..4961a810 --- /dev/null +++ b/src/book/GenreEnum.java @@ -0,0 +1,25 @@ +package book; + +public enum GenreEnum { + FICTION, + NON_FICTION, + MYSTERY, + FANTASY, + SCIENCE_FICTION, + BIOGRAPHY, + HISTORICAL, + ROMANCE, + THRILLER, + CHILDREN, + YOUNG_ADULT, + CLASSICS, + SELF_HELP, + POETRY, + DYSTOPIAN, + ADVENTURE, + HORROR, + GRAPHIC_NOVEL, + RELIGIOUS, + COOKBOOK, + ANTHOLOGY +} diff --git a/src/book/bookSubClasses/Journals.java b/src/book/bookSubClasses/Journals.java new file mode 100644 index 00000000..ebd50747 --- /dev/null +++ b/src/book/bookSubClasses/Journals.java @@ -0,0 +1,13 @@ +package book.bookSubClasses; + +import Shared.CustomDate; +import book.Book; +import book.BookEdition; +import book.GenreEnum; +import person.Author; + +public class Journals extends Book { + public Journals(long bookId, Author author, String name, String title, double price, BookEdition edition, CustomDate dateofpurches, GenreEnum genre) { + super(bookId, author, name, title, price, edition, dateofpurches,genre); + } +} diff --git a/src/book/bookSubClasses/Magazines.java b/src/book/bookSubClasses/Magazines.java new file mode 100644 index 00000000..e5b77178 --- /dev/null +++ b/src/book/bookSubClasses/Magazines.java @@ -0,0 +1,13 @@ +package book.bookSubClasses; + +import Shared.CustomDate; +import book.Book; +import book.BookEdition; +import book.GenreEnum; +import person.Author; + +public class Magazines extends Book { + public Magazines(long bookId, Author author, String name, String title, double price, BookEdition edition, CustomDate dateofpurches, GenreEnum genre) { + super(bookId, author, name, title, price, edition, dateofpurches, genre); + } +} diff --git a/src/book/bookSubClasses/StudyBooks.java b/src/book/bookSubClasses/StudyBooks.java new file mode 100644 index 00000000..50980edc --- /dev/null +++ b/src/book/bookSubClasses/StudyBooks.java @@ -0,0 +1,13 @@ +package book.bookSubClasses; + +import Shared.CustomDate; +import book.Book; +import book.BookEdition; +import book.GenreEnum; +import person.Author; + +public class StudyBooks extends Book { + public StudyBooks(long bookId, Author author, String name, String title, double price, BookEdition edition, CustomDate dateofpurches, GenreEnum genre) { + super(bookId, author, name, title, price, edition, dateofpurches, genre); + } +} diff --git a/src/description.puml b/src/description.puml new file mode 100644 index 00000000..b8b52e85 --- /dev/null +++ b/src/description.puml @@ -0,0 +1,116 @@ +@startuml +package person { + + class Person { + - name: String + # whoyouare(): String + } + + class Reader { + - member_record: MemberRecord + --- + + setMember_record(memberRecord: MemberRecord): void + + getMember_record(): MemberRecord + # whoyouare(): String + } + + class Author { + - books: Set + + show_book(): Set + + setBooks(books: Set): void + + new_book(book: Book): boolean + + whoyouare(): String + } + + class Librarian { + - password: String + - library: Library + + getLibrary(): Library + + createRecord(reader: Reader, memberRecord: MemberRecord): boolean + + addReaderToLibrary(reader: Reader): boolean + + giveBackBook(bookId: long): boolean + + whoyouare(): String + } + + class MemberRecord { + - member_id: long + - library: Library + - reader: Reader + - type: membershipType + - date_of_membership: CustomDate + - lendedBooks: Set + - MAX_LENDED_BOOKS: int + - dept: double + + MemberRecord() + + MemberRecord(member_id: long, type: membershipType, reader: Reader, library: Library) + + getDept(): double + + getLendedBooks(): Set + + getLibrary(): Library + + setLibrary(library: Library): void + + addBookToLendedBooks(book: Book): boolean + + returnBook(id: long): boolean + + toString(): String + } + + Person <|-- Author : Inherits + Person <|-- Reader : Inherits + Person <|-- Librarian : Inherits + Reader --> MemberRecord : Has a + MemberRecord --> Library : Uses +} + +package book { + class Book { + + getPrice(): double + + getName(): String + + setStatus(status: BookStatus): void + + setOwner(owner: MemberRecord): void + + get_author(): Author + + getGenre(): GenreEnum + + lendBook(record: MemberRecord): void + + getBookId(): long + } + + class BookStatus { + <> + + AVAILABLE + + ON_HOLD + + LENT_OUT + } + + class GenreEnum { + <> + + FICTION + + NON_FICTION + + SCI_FI + + BIOGRAPHY + + FANTASY + } +} + +package library { + class Library { + - books: Map + - readers: Map + + Library() + + Library(books: Map, readers: Map) + + get_book(): Map + + get_book(id: long): Book + + get_book(name: String): Book + + get_book(author: Author): Set + + deleteBook(id: long): boolean + + getBooksByGenre(genre: GenreEnum): List + + get_readers(): Map + + searchForReader(name: String): Reader + + new_book(book: Book): boolean + + addReader(reader: Reader): boolean + + lendBook(bookId: long, readerName: String): boolean + + toString(): String + } +} + +Author --> Book : Has a Set of +Library --> Book : Contains +Library --> Reader : Contains +Library --> MemberRecord : Uses +@enduml diff --git a/src/library/Library.java b/src/library/Library.java new file mode 100644 index 00000000..018808c5 --- /dev/null +++ b/src/library/Library.java @@ -0,0 +1,139 @@ +package library; + +import book.Book; + +import book.BookStatus; +import book.GenreEnum; +import person.Author; +import person.reader.MemberRecord; +import person.reader.Reader; + +import java.util.*; + +public class Library { + private Map books; + private Map readers; + + public Library() { + this.books = new HashMap<>(); + this.readers = new HashMap<>(); + } + + public Library(Map books, Map readers) { + this.books = (books != null) ? books : new HashMap<>(); + this.readers = (readers != null) ? readers : new HashMap<>(); + } + + public Map get_book() { + return books; + } + + public Book get_book(long id) { + return books.get(id); + } + + public Book get_book(String name) { + for ( Book book : books.values()) { + if (book.getName().equals(name)) { + return book; + } + } + return null; + } + + public Set get_book(Author author) { + Set bookSet = new HashSet<>(); + for (Book book : books.values()) { + if (book.get_author().equals(author)) { + bookSet.add(book); + } + } + return bookSet.isEmpty() ? null : bookSet; + } + + public boolean deleteBook(long id){ + Book book = books.remove(id); + return book != null; + } + + public List getBooksByGenre(GenreEnum genre) { + List bookList = new ArrayList<>(); + for (Book book : books.values()) { + if (book.getGenre().equals(genre)) { + bookList.add(book); + } + } + return bookList; + } + + public Map get_readers() { + return readers; + } + + public Reader searchForReader(String name) { + return readers.get(name); + } + + public boolean new_book(Book book) { + if (book == null || books.containsKey(book.getBookId())) { + return false; + } else { + books.put(book.getBookId(), book); + return true; + } + } + + public boolean addReader(Reader reader){ + if (reader != null){ + readers.put(reader.name,reader); + System.out.println(reader.name + " is added to library"); + return true; + }else { + System.out.println("Reader is null"); + return false; + } + } + + + public boolean lendBook(long bookId, String readerName) { + Book book = get_book(bookId); + boolean success = false; + if (book == null) { + System.out.println("Book with ID " + bookId + " is not in the library."); + return false; + } else if (book.getStatus()!= BookStatus.AVAILABLE) { + System.out.println("Book is not available"); + return false; + } + + Reader reader = searchForReader(readerName); + if (reader == null) { + System.out.println("Reader " + readerName + " is not signed in!"); + return false; + } + + MemberRecord record = reader.getMember_record(); + if (record != null) { + success = record.addBookToLendedBooks(book); + } else { + System.out.println("Please create a record to lend a book."); + return false; + } + + if (success) { + book.lendBook(record); + System.out.println("Book with ID " + bookId + " successfully lent to " + readerName + "."); + } else { + System.out.println("Failed to lend book with ID " + bookId + " to " + readerName + "."); + } + return success; + } + + @Override + public String toString() { + return "Library{" + + "books=" + books + + ", readers=" + readers + + '}'; + } +} diff --git a/src/person/Author.java b/src/person/Author.java new file mode 100644 index 00000000..6d2db48c --- /dev/null +++ b/src/person/Author.java @@ -0,0 +1,44 @@ +package person; + +import book.Book; + +import java.util.HashSet; +import java.util.Set; + +public class Author extends Person{ + private Set books; + + public Author(String name) { + this.name = name; + this.books = new HashSet<>(); + } + + public Author(String name, Set books) { + this.name = name; + this.books = books; + } + + + public Set show_book() { + return books; + } + + public void setBooks(Set books) { + this.books = books; + } + + public boolean new_book(Book book){ + if(!books.contains(book)){ + books.add(book); + return true; + }else return false; + } + + @Override + public String whoyouare() { + return "Author{" + + "name" + name + + "books=" + books + + '}'; + } +} diff --git a/src/person/Librarian.java b/src/person/Librarian.java new file mode 100644 index 00000000..73896783 --- /dev/null +++ b/src/person/Librarian.java @@ -0,0 +1,78 @@ +package person; + +import book.Book; +import book.BookStatus; +import book.GenreEnum; +import library.Library; +import person.reader.MemberRecord; +import person.reader.Reader; + + +import java.util.*; + +public class Librarian extends Person{ + private String password; + private Library library; + + public Library getLibrary() { + return library; + } + + public Librarian(String name, String password, Library library) { + this.name = name; + this.password = password; + this.library = library; + } + + @Override + public String whoyouare() { + return "Librarian :" + + "Name :" + name; + } + + public boolean createRecord(Reader reader, MemberRecord memberRecord){ + reader.setMember_record(memberRecord); + return true; + } + + public boolean addReaderToLibrary(Reader reader){ + boolean success = library.addReader(reader); + if (success){ + System.out.println(reader.name + " is added to " + library); + }else System.out.println("Not successful"); + return success; + } + + public boolean giveBackBook(long bookId) { + Book book = library.get_book(bookId); + MemberRecord record; + + if (book == null) { + System.out.println("Book with ID " + bookId + " signed in to library."); + return false; + } else if (book.getStatus()!=BookStatus.ON_HOLD) { + System.out.println("Book is not lended!"); + return false; + }else { + record = book.get_owner(); + book.giveBackBook(); + } + + if (record != null){ + record.returnBook(bookId); + System.out.println("Book with ID " + bookId + " has been successfully returned."); + return true; + } + System.out.println("Book with ID " + bookId + " has no owner record."); + return false; + } + + @Override + public String toString() { + return "Librarian{" + + "password='" + password + '\'' + + ", library=" + library + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/src/person/Person.java b/src/person/Person.java new file mode 100644 index 00000000..022dd3ef --- /dev/null +++ b/src/person/Person.java @@ -0,0 +1,7 @@ +package person; + +public abstract class Person { + public String name; + + public abstract String whoyouare(); +} diff --git a/src/person/reader/MemberRecord.java b/src/person/reader/MemberRecord.java new file mode 100644 index 00000000..3ce5f976 --- /dev/null +++ b/src/person/reader/MemberRecord.java @@ -0,0 +1,84 @@ +package person.reader; + +import Shared.CustomDate; +import book.Book; +import book.BookStatus; +import library.Library; + +import java.util.*; + +public class MemberRecord { + private long member_id; + private Library library; + private Reader reader; + private membershipType type; + private CustomDate date_of_membership; + private Set lendedBooks = new HashSet<>(); + private final int MAX_LENDED_BOOKS = 5; + private double dept; + + public MemberRecord() { + } + + public MemberRecord(long member_id, membershipType type, Reader reader, Library library) { + this.member_id = member_id; + this.type = type; + this.reader = reader; + this.library = library; + dept = 0; + } + + public double getDept() { + return dept; + } + + public Set getLendedBooks() { + return lendedBooks; + } + + public Library getLibrary() { + return library; + } + + public void setLibrary(Library library) { + this.library = library; + } + + public boolean addBookToLendedBooks(Book book) { + if (lendedBooks.size()<6){ + lendedBooks.add(book); + System.out.println("Kitap fiyatları " + book.getPrice()); + dept += book.getPrice(); + } + return true; + } + + public boolean returnBook(long id) { + Book book = library.get_book(id); + + if (book == null) { + System.out.println("Book does not exist!"); + return false; + } + + if (!lendedBooks.contains(book)) { + System.out.println("This book was not lent out!"); + return false; + } + + book.setStatus(BookStatus.AVAILABLE); + lendedBooks.remove(book); + book.setOwner(null); + System.out.println("Book " + book.getName() + " has been returned successfully."); + + dept -= book.getPrice(); + return true; + } + + @Override + public String toString() { + return "MemberRecord{" + + "Reader = " + this.reader + + '}'; + } +} diff --git a/src/person/reader/Reader.java b/src/person/reader/Reader.java new file mode 100644 index 00000000..af9fe7b3 --- /dev/null +++ b/src/person/reader/Reader.java @@ -0,0 +1,62 @@ +package person.reader; + +import book.Book; +import book.BookStatus; +import person.Person; + +import java.util.Collection; +import java.util.Objects; +import java.util.Set; + +public class Reader extends Person { + private MemberRecord member_record; + + public Reader(String name) { + this.name = name; + } + + public Reader(String name, MemberRecord member_record) { + this.name = name; + this.member_record = member_record; + } + + public MemberRecord getMember_record(){ + if (member_record == null) { + System.out.println("Not a member"); + return new MemberRecord(); + }; + return member_record; + } + + public void setMember_record(MemberRecord member_record) { + this.member_record = member_record; + } + + @Override + public String whoyouare() { + return "Reader{" + + ", name='" + name + '\'' + + "member_record=" + member_record + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Reader reader = (Reader) o; + return Objects.equals(name, reader.name); + } + + @Override + public int hashCode() { + return Objects.hashCode(name); + } + + @Override + public String toString() { + return "Reader{" + + "name='" + name + '\'' + + '}'; + } +} diff --git a/src/person/reader/membershipType.java b/src/person/reader/membershipType.java new file mode 100644 index 00000000..b199ec89 --- /dev/null +++ b/src/person/reader/membershipType.java @@ -0,0 +1,9 @@ +package person.reader; + +public enum membershipType { + BASIC, + PREMIUM, + STUDENT, + SENIOR, + CORPORATE; +}