Browse Source

Minor updates

Main.java
- removed redundant newBook()

Book.java
- Added a condition if the book is not overdue

BookFactory.java
- Removed empty newBook()
- Added “throw new NullPointerException()” on both getBook() if Book is
not found
master
BinHong Lee 8 years ago
parent
commit
2ca886ce92
3 changed files with 18 additions and 21 deletions
  1. +6
    -1
      Book.java
  2. +10
    -15
      BookFactory.java
  3. +2
    -5
      Main.java

+ 6
- 1
Book.java View File

@@ -1,6 +1,6 @@
/* /*
* Written by : Bin Hong Lee * Written by : Bin Hong Lee
* Last edited : 4/27/2016
* Last edited : 5/31/2016
*/ */


class Book class Book
@@ -85,6 +85,11 @@ class Book
double fine; double fine;
boolean monChange = false; boolean monChange = false;


if(currentDay[0] < dueDate[0] || (currentDay[0] == dueDate[0] && currentDay[1] < dueDate[1]) || (currentDay[0] == dueDate[0] && currentDay[1] == dueDate[1] && currentDay[2] <= dueDate[2]))
{
return 0;
}

while(currentDay[0] > dueDate[0]) while(currentDay[0] > dueDate[0])
{ {
currentDay[0]--; currentDay[0]--;


+ 10
- 15
BookFactory.java View File

@@ -1,6 +1,6 @@
/* /*
* Written by : Bin Hong Lee * Written by : Bin Hong Lee
* Last edited : 4/27/2016
* Last edited : 5/31/2016
*/ */


import java.util.*; import java.util.*;
@@ -15,16 +15,6 @@ class BookFactory
id = 0; id = 0;
} }


public Book newBook()
{
Book temp = new Book(id);
books.add(temp);

id++;

return temp;
}

public Book newBook(String title) public Book newBook(String title)
{ {
Book temp = new Book(title, id); Book temp = new Book(title, id);
@@ -37,7 +27,14 @@ class BookFactory


public Book getBook(int index) public Book getBook(int index)
{ {
return books.get(index);
try
{
return books.get(index);
}
catch (Exception e)
{
throw new NullPointerException();
}
} }


public Book getBook(String title) public Book getBook(String title)
@@ -52,8 +49,6 @@ class BookFactory
} }
} }


System.out.println("Error 404 : Book not found");

return newBook();
throw new NullPointerException();
} }
} }

+ 2
- 5
Main.java View File

@@ -1,10 +1,11 @@
/* /*
* Written by : Bin Hong Lee * Written by : Bin Hong Lee
* Last edited : 4/27/2016
* Last edited : 5/31/2016
*/ */


class Main class Main
{ {
Exception BookNotFound = new Exception("Error 404 : Book not found");
static BookFactory books = new BookFactory(); static BookFactory books = new BookFactory();


public static void main(String[] args) public static void main(String[] args)
@@ -12,8 +13,4 @@ class Main


} }


public static void newBook()
{
books.newBook();
}
} }

Loading…
Cancel
Save