-
Notifications
You must be signed in to change notification settings - Fork 0
/
Library Fine.php
50 lines (36 loc) · 1.7 KB
/
Library Fine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
PROBLEM:
Your local library needs your help! Given the expected and actual return dates for a library book, create a program that calculates the fine (if any). The fee structure is as follows:
1. If the book is returned on or before the expected return date, no fine will be charged (i.e.: fine = 0).
2. if the book is returned after the expected return day but still within the same calendar month and year as the expected return date, fine = 15 Hackos x (the number of days late).
3. If the book is returned after the expected return month but still within the same calendar year as tne expected return date, the fine = 500 Hackos x (the number of months late).
4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of 10000 Hackos.
Charges are based only on the least precise measure of lateness. For example, whether a book is due January 1, 2017 or December 31, 2017, if it is returned January 1, 2018, that is a year late and the fine would be 10, 000 Hlackos.
Example
d1, m1, y1 = 14, 7, 2018
d2, m2, m2 = 5,7, 2018
The first values are the return date and the second are the due date. The years are the same and the months are the same. The book is 14 - 5 = 9 days late. Return 9 * 15 = 135.
*/
// Solution
function libraryFine($d1, $m1, $y1, $d2, $m2, $y2) {
// Write your code here
$year = false;
// Check year
if($y1 > $y2){
return ($y1-$y2)*10000;
}
else if($m1 > $m2 && $y1 == $y2){
return ($m1-$m2)* 500;
}
else if($d1 > $d2 && $m1 == $m2 && $y1 == $y2){
return ($d1-$d2)*15;
}
else{
return 0;
}
// Check Month
// Check Day
}
echo libraryFine(14, 7, 2018, 5, 7, 2018);
?>