BookFactory.java - newBook() now returns the new ‘Book’ created instead of ‘void’ - if getBook() failed, it now returns an empty ‘Book’ Book.java - overdueFine(int[]) is now rewrittenmaster
@@ -83,20 +83,36 @@ class Book | |||||
public double overdueFine(int[] currentDay) | public double overdueFine(int[] currentDay) | ||||
{ | { | ||||
double fine; | double fine; | ||||
boolean monChange = false; | |||||
if(currentDay[0] > dueDate[0] || currentDay[1] > (dueDate[1] + 1)) | |||||
while(currentDay[0] > dueDate[0]) | |||||
{ | { | ||||
return 5; | |||||
} | |||||
else if(currentDay[1] > dueDate[1]) | |||||
{ | |||||
fine = (double)(currentDay[2] + 30 - dueDate[2]) * 0.25; | |||||
currentDay[0]--; | |||||
currentDay[1]+=12; | |||||
} | } | ||||
else | |||||
while(currentDay[1] > dueDate[1]) | |||||
{ | { | ||||
fine = (double)(currentDay[2] - dueDate[2]) * 0.25; | |||||
int mon = currentDay[1] % 12; | |||||
if(mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) | |||||
{ | |||||
currentDay[2]+=31; | |||||
} | |||||
else if(mon == 2) | |||||
{ | |||||
currentDay[2]+=28; | |||||
} | |||||
else | |||||
{ | |||||
currentDay[2]+=30; | |||||
} | |||||
currentDay[1]--; | |||||
} | } | ||||
fine = (double)(currentDay[2] - dueDate[2]) * 0.25; | |||||
if(fine > 5) | if(fine > 5) | ||||
{ | { | ||||
return 5; | return 5; | ||||
@@ -15,20 +15,24 @@ class BookFactory | |||||
id = 0; | id = 0; | ||||
} | } | ||||
public void newBook() | |||||
public Book newBook() | |||||
{ | { | ||||
Book temp = new Book(id); | Book temp = new Book(id); | ||||
books.add(temp); | books.add(temp); | ||||
id++; | id++; | ||||
return temp; | |||||
} | } | ||||
public void newBook(String title) | |||||
public Book newBook(String title) | |||||
{ | { | ||||
Book temp = new Book(title, id); | Book temp = new Book(title, id); | ||||
books.add(temp); | books.add(temp); | ||||
id++; | id++; | ||||
return temp; | |||||
} | } | ||||
public Book getBook(int index) | public Book getBook(int index) | ||||
@@ -50,7 +54,6 @@ class BookFactory | |||||
System.out.println("Error 404 : Book not found"); | System.out.println("Error 404 : Book not found"); | ||||
Book empty = new Book(); | |||||
return empty; | |||||
return newBook(); | |||||
} | } | ||||
} | } |