Untitled

 avatar
unknown
plain_text
2 years ago
819 B
5
Indexable
<?php
class Person
{
    private $income;
    private $expense;

    public function __construct($income, $expense)
    {
        if ($income > 0 && $expense > 0) {
            $this->income = $income;
            $this->expense = $expense;
        }
    }

    public function getTotal()
    {
        return ($this->income - $this->expense);
    }
}

class Compare
{
    public function comparePersons(Person $a, Person $b)
    {
        if ($a->getTotal() > $b->getTotal()) {
            return "a > b";
        } elseif ($a->getTotal() < $b->getTotal()) {
            return "b > a";
        } else {
            return "a = b";
        }
    }
}

$p1 = new Person(300000000, 100000);
$p2 = new Person(300000000, 100000);

$c = new Compare();
echo $c->comparePersons($p1, $p2);
Editor is loading...