Bläddra i källkod

overdueFine(int[]), newBook()

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 rewritten
master
BinHong Lee 8 år sedan
förälder
incheckning
94a4a90cec
2 ändrade filer med 31 tillägg och 12 borttagningar
  1. +24
    -8
      Book.java
  2. +7
    -4
      BookFactory.java

+ 24
- 8
Book.java Visa fil

@@ -83,20 +83,36 @@ class Book
public double overdueFine(int[] currentDay)
{
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)
{
return 5;


+ 7
- 4
BookFactory.java Visa fil

@@ -15,20 +15,24 @@ class BookFactory
id = 0;
}

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

id++;

return temp;
}

public void newBook(String title)
public Book newBook(String title)
{
Book temp = new Book(title, id);
books.add(temp);

id++;

return temp;
}

public Book getBook(int index)
@@ -50,7 +54,6 @@ class BookFactory

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

Book empty = new Book();
return empty;
return newBook();
}
}

Laddar…
Avbryt
Spara