Pārlūkot izejas kodu

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 pirms 8 gadiem
vecāks
revīzija
2ca886ce92
3 mainītis faili ar 18 papildinājumiem un 21 dzēšanām
  1. +6
    -1
      Book.java
  2. +10
    -15
      BookFactory.java
  3. +2
    -5
      Main.java

+ 6
- 1
Book.java Parādīt failu

@@ -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 Parādīt failu

@@ -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 Parādīt failu

@@ -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();
}
}

Notiek ielāde…
Atcelt
Saglabāt