-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomer.php
87 lines (66 loc) · 2.02 KB
/
Customer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Created by JetBrains PhpStorm.
* User: merklik
* Date: 4/27/13
* Time: 10:50 AM
* To change this template use File | Settings | File Templates.
*/
namespace Refactoring;
class Customer
{
private $_name;
private $_rentals = array();
function __construct($name)
{
$this->_name = $name;
}
public function addRental(Rental $arg)
{
$this->_rentals[] = $arg;
}
public function getName()
{
return $this->_name;
}
public function statement()
{
$result = "Rental Record for " . $this->getName() . "\n";
foreach ($this->_rentals as $each) {
//show figures for this rental
$result .= "\t" . $each->getMovie()->getTitle() . "\t" . $each->getCharge() . "\n";
}
//add footer lines
$result .= "Amount owed is " . $this->getTotalAmount() . "\n";
$result .= "You earned " . $this->getTotalFrequenterPoints() . " frequent renter points";
return $result;
}
public function statementHTML()
{
$result = "<HTML><BODY>Rental Record for " . $this->getName() . "<br/>";
foreach ($this->_rentals as $each) {
//show figures for this rental
$result .= $each->getMovie()->getTitle() . ": " . $each->getCharge() . "<br/>";
}
//add footer lines
$result .= "Amount owed is " . $this->getTotalAmount() . "<br/>";
$result .= "You earned " . $this->getTotalFrequenterPoints() . " frequent renter points</BODY></HTML>";
return $result;
}
private function getTotalAmount()
{
$totalAmount = 0;
foreach ($this->_rentals as $each) {
$totalAmount += $each->getCharge();
}
return $totalAmount;
}
private function getTotalFrequenterPoints()
{
$frequentRenterPoints = 0;
foreach ($this->_rentals as $each) {
$frequentRenterPoints += $each->getFrequentRenterPoints();
}
return $frequentRenterPoints;
}
}