Bläddra i källkod

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 år sedan
förälder
incheckning
2ca886ce92
3 ändrade filer med 18 tillägg och 21 borttagningar
  1. +6
    -1
      Book.java
  2. +10
    -15
      BookFactory.java
  3. +2
    -5
      Main.java

+ 6
- 1
Book.java Visa fil

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

class Book
@@ -85,6 +85,11 @@ class Book
double fine;
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])
{
currentDay[0]--;


+ 10
- 15
BookFactory.java Visa fil

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

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

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

id++;

return temp;
}

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

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)
@@ -52,8 +49,6 @@ class BookFactory
}
}

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

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

+ 2
- 5
Main.java Visa fil

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

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

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

}

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

Laddar…
Avbryt
Spara