瀏覽代碼

Added Title, Implemented Main, newBook, getBook

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
master
BinHong Lee 8 年之前
父節點
當前提交
915f101b76
共有 3 個文件被更改,包括 58 次插入0 次删除
  1. +18
    -0
      Book.java
  2. +26
    -0
      BookFactory.java
  3. +14
    -0
      Main.java

+ 18
- 0
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;


+ 26
- 0
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;
}
}

+ 14
- 0
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();
}
}

Loading…
取消
儲存