Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added Librarian Concept + Media support #294

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,57 @@
package com.codedifferently.lesson10.library;

import com.codedifferently.lesson10.library.exceptions.BookCheckedOutException;

/** Represents a librarian of a library. */
public class Librarian extends Patron {
00USER1X marked this conversation as resolved.
Show resolved Hide resolved

/**
* Create a new librarian with the given name and email.
*
* @param name The name of the librarian.
* @param email The email of the librarian.
*/
public Librarian(String name, String email) {
super(name, email);
}

/**
* Check out a book to a patron.
*
* @param book The book to check out.
* @return True if the book was checked out, false otherwise.
*/
@Override
public boolean checkOutBook(Book book) {
if (this instanceof Librarian) {
return super.checkOutBook(book);
}
return false; // Librarians cannot check out books to regular patrons
}

/**
* Return a book to the library.
*
* @param book The book to return.
* @return True if the book was returned, false otherwise.
*/
@Override
public boolean checkInBook(Book book) {
if (this instanceof Librarian) {
return super.checkInBook(book);
}
return false; // Librarians cannot return books for regular patrons
}

/**
* Remove a book from the library.
*
* @param book The book to remove.
*/
public void removeBook(Book book) throws BookCheckedOutException {
if (book.isCheckedOut()) {
throw new BookCheckedOutException("Cannot remove checked out book.");
}
book.setLibrary(null);
}
}
Expand Up @@ -59,6 +59,36 @@ public Set<Book> getCheckedOutBooks() throws LibraryNotSetException {
return this.library.getCheckedOutByPatron(this);
}

/**
* Check out a book from the library.
*
* @param book The book to check out.
* @return True if the book was successfully checked out, false otherwise.
*/
public boolean checkOutBook(Book book) {
try {
return this.library.checkOutBook(book, this);
} catch (Exception e) {
System.out.println(e.getMessage());
return false;
}
}

/**
* Return a book to the library.
*
* @param book The book to return.
* @return True if the book was successfully returned, false otherwise.
*/
public boolean checkInBook(Book book) {
try {
return this.library.checkInBook(book, this);
} catch (Exception e) {
System.out.println(e.getMessage());
return false;
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
@@ -0,0 +1,25 @@
package com.codedifferently.lesson10.library.media;

public class Dvd {
00USER1X marked this conversation as resolved.
Show resolved Hide resolved
private String title;
private String director;
private int duration;

public Dvd(String title, String director, int duration) {
this.title = title;
this.director = director;
this.duration = duration;
}

public String getTitle() {
return title;
}

public String getDirector() {
return director;
}

public int getDuration() {
return duration;
}
}
@@ -0,0 +1,25 @@
package com.codedifferently.lesson10.library.media;

public class Magazine {
private String title;
private String issueNumber;
private String publicationDate;

public Magazine(String title, String issueNumber, String publicationDate) {
this.title = title;
this.issueNumber = issueNumber;
this.publicationDate = publicationDate;
}

public String getTitle() {
return title;
}

public String getIssueNumber() {
return issueNumber;
}

public String getPublicationDate() {
return publicationDate;
}
}
@@ -0,0 +1,25 @@
package com.codedifferently.lesson10.library.media;

public class Newspaper {
private String title;
private String edition;
private String publicationDate;

public Newspaper(String title, String edition, String publicationDate) {
this.title = title;
this.edition = edition;
this.publicationDate = publicationDate;
}

public String getTitle() {
return title;
}

public String getEdition() {
return edition;
}

public String getPublicationDate() {
return publicationDate;
}
}
@@ -0,0 +1 @@

@@ -0,0 +1 @@

@@ -0,0 +1 @@