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 workmaster
@@ -1,5 +1,6 @@ | |||||
class Book | class Book | ||||
{ | { | ||||
private String title; | |||||
private int id; | private int id; | ||||
//( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE) | //( AVAILABLE || RENTED || RESERVED || NOT AVAILABLE) | ||||
private String status; | private String status; | ||||
@@ -11,6 +12,23 @@ class Book | |||||
this.status = status; | 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() | public String getStatus() | ||||
{ | { | ||||
return status; | return status; | ||||
@@ -18,8 +18,34 @@ class BookFactory | |||||
id++; | id++; | ||||
} | } | ||||
public void newBook(String title) | |||||
{ | |||||
Book temp = new Book(title, id, "NOT AVAILABLE"); | |||||
books.add(temp); | |||||
id++; | |||||
} | |||||
public Book getBook(int index) | public Book getBook(int index) | ||||
{ | { | ||||
return books.get(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; | |||||
} | |||||
} | } |
@@ -0,0 +1,14 @@ | |||||
class Main | |||||
{ | |||||
static BookFactory books = new BookFactory(); | |||||
public static void main(String[] args) | |||||
{ | |||||
} | |||||
public static void newBook() | |||||
{ | |||||
books.newBook(); | |||||
} | |||||
} |