From 915f101b76cf0f171187f99995925db21e9a5bae Mon Sep 17 00:00:00 2001 From: BinHong Lee Date: Wed, 27 Apr 2016 17:05:47 -0700 Subject: [PATCH] Added Title, Implemented Main, newBook, getBook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Book.java - Added String type ‘title’ - Added new constructor to include ’title’ Main.java - Added Main.java (mostly still empty) BookFactory.java - Added newBook(String) for the new ‘title’ implementation - Added getBook(String) to look through ArrayList for Book with the given ‘title’ - Error handling for both getBook still needs more work --- Book.java | 18 ++++++++++++++++++ BookFactory.java | 26 ++++++++++++++++++++++++++ Main.java | 14 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 Main.java diff --git a/Book.java b/Book.java index 3102c79..9f860da 100644 --- a/Book.java +++ b/Book.java @@ -1,5 +1,6 @@ class Book { + private String title; private int id; //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE) private String status; @@ -11,6 +12,23 @@ class Book this.status = status; } + public Book(String title, int id, String status) + { + this.title = title; + this.id = id; + this.status = status; + } + + public String getTitle() + { + if (title!=null) + { + return title; + } else { + return "UNDEFINED"; + } + } + public String getStatus() { return status; diff --git a/BookFactory.java b/BookFactory.java index 03671a4..c568704 100644 --- a/BookFactory.java +++ b/BookFactory.java @@ -18,8 +18,34 @@ class BookFactory id++; } + public void newBook(String title) + { + Book temp = new Book(title, id, "NOT AVAILABLE"); + books.add(temp); + + id++; + } + public Book getBook(int index) { return books.get(index); } + + public Book getBook(String title) + { + for (int i = 0; i < books.size(); i++) + { + Book temp = books.get(i); + + if(temp.getTitle() == title) + { + return temp; + } + } + + System.out.println("Error 404 : Book not found"); + + Book empty = new Book(); + return empty; + } } diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..f94d66a --- /dev/null +++ b/Main.java @@ -0,0 +1,14 @@ +class Main +{ + static BookFactory books = new BookFactory(); + + public static void main(String[] args) + { + + } + + public static void newBook() + { + books.newBook(); + } +}