Преглед на файлове

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 години
родител
ревизия
94a4a90cec
променени са 2 файла, в които са добавени 31 реда и са изтрити 12 реда
  1. +24
    -8
      Book.java
  2. +7
    -4
      BookFactory.java

+ 24
- 8
Book.java Целия файл

@@ -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 Целия файл

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

Зареждане…
Отказ
Запис