Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book
- {
- private String title;
- private String author;
- private String summary;
- public Book() {
- title = "";
- author = "";
- summary = "";
- }
- public Book(String title, String author, String summary) {
- this.title = title;
- this.author = author;
- this.summary = summary;
- }
- public String getTitle() {
- return title;
- }
- public String getAuthor() {
- return author;
- }
- public String getSummary() {
- return summary;
- }
- }
- import java.util.*;
- public class Library
- {
- private String location;
- private String openingHours;
- private Book book;
- private Map<Book,Integer> bookList = new HashMap<Book,Integer>();
- public Library(String location, String openingHours) {
- this.location = location;
- this.openingHours = openingHours;
- }
- public void addBook(Book book) {
- //If the book doesn't exist add it: otherwise increase the quantity of the book
- if (bookList.containsKey(book))
- bookList.put(book, bookList.get(book) + 1);
- else
- bookList.put(book, 1);
- }
- public String printOpeningHours() {
- return openingHours;
- }
- public String printAddress() {
- return location;
- }
- public void borrowBook(Book book) {
- bookList.put(book, bookList.get(book) - 1);
- }
- public void returnBook() {
- bookList.put(book, bookList.get(book) + 1);
- }
- public String printAvailableBooks() {
- ArrayList <String> available = new ArrayList();
- for (Book books: bookList.keySet())
- available.add(books.toString());
- return available.toString();
- }
- public boolean isBorrowed() {
- int value = 0;
- for (Book bq: bookList.keySet()) {
- value = bookList.get(bq);
- if (value > 0)
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- Library l1 = new Library("111 Your Street", "9am");
- l1.addBook(new Book("Test", "Author", "Test summary"));
- l1.addBook(new Book("Test2", "Author2", "Test summary2"));
- l1.addBook(new Book("Test3", "Author3", "Test summary3"));
- System.out.println(l1.printAvailableBooks());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement