Sfoglia il codice sorgente

Main.java

- Added returnBook(User, Book) which will update both the users and the
books upon success on returning the book
- Added currentDay() that would return the current date in int array
- Added calDueDate(int) that takes the current date from currentDay()
and calculate the due date from there
master
BinHong Lee 8 anni fa
parent
commit
729bbf9033
1 ha cambiato i file con 100 aggiunte e 0 eliminazioni
  1. +100
    -0
      Main.java

+ 100
- 0
Main.java Vedi File

@@ -3,14 +3,114 @@
* Last edited : 5/31/2016
*/

import java.util.Date

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

public static void main(String[] args)
{

}

public static boolean returnBook(User user, Book book)
{
User newUser = user;

if(newUser.returnBook(book.getId()))
{
book.returned();

books.update(book);
users.update(user, newUser);

return true;
}

return false;
}

public static int[] calDueDate(int days)
{
int[] dueDate = currentDay();

for (int i = 0; i < days; i++)
{
if(dueDate[2] < 28)
{
dueDate[2]++;
}
else if(dueDate[1] == 12)
{
if(dueDate[2] == 31)
{
dueDate[0]++;
dueDate[1] = 1;
dueDate[2] = 1;
}
}
else if(dueDate[1] == 2)
{
if((dueDate[0] % 4) == 0)
{
if(dueDate[2] == 29)
{
dueDate[1]++;
dueDate[2] = 1;
}
else
{
dueDate[2]++;
}
}
else if(dueDate[2] == 28)
{
dueDate[1]++;
dueDate[2] = 1;
}
else
{
dueDate[2]++;
}
}
else if(dueDate[1] == 4 || dueDate[1] == 6 || dueDate[1] == 9 || dueDate[1] == 11)
{
if(dueDate[2] == 30)
{
dueDate[1]++;
dueDate[2] = 1;
}
else
{
dueDate[2]++;
}
}
else if(dueDate[2] == 31)
{
dueDate[1]++;
dueDate[2] = 1;
}
else
{
dueDate[2]++;
}
}

return dueDate;
}

public static int[] currentDay()
{
int[] currentDay = new int[3]();

currentDay[0] = date.getYear();
currentDay[1] = date.getMonth();
currentDay[2] = date.getDate();

return currentDay;
}
}

Caricamento…
Annulla
Salva