Advertisement
Tpojka

48308

Jan 29th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. class Tariff
  2. {
  3.     protected $total = 0;
  4.     protected $yearlyStaticExpenses = 0;
  5.     protected $name = '';
  6.     protected $consumptionCosts = 0;
  7.  
  8.     abstract protected function setYearlyStaticExpenses($yearlyStaticExpenses = null);
  9.  
  10.     abstract protected function calculate();
  11.  
  12.     protected function getYearlyStaticExpenses()
  13.     {
  14.         return $this->yearlyStaticExpenses;
  15.     }
  16.  
  17.     protected function setPrice($price)
  18.     {
  19.         $this->price = $price;
  20.         return $this;
  21.     }
  22.  
  23.     protected function getPrice()
  24.     {
  25.         return $this->price;
  26.     }
  27.  
  28.     protected function setName($name)
  29.     {
  30.         $this->name = $name;
  31.         return $this;
  32.     }
  33.  
  34.     protected function getName()
  35.     {
  36.         return $this->name;
  37.     }
  38.  
  39.     protected function setConsumptionCosts($consumptionCosts)
  40.     {
  41.         $this->consumptionCosts = $consumptionCosts;
  42.         return $this;
  43.     }
  44.  
  45.     protected function getConsumptionCosts()
  46.     {
  47.         return $this->consumptionCosts;
  48.     }
  49.  
  50.     protected function centsToEur(int $cents)
  51.     {
  52.         return sprintf("%2f", round($cents / 100), 2);
  53.     }
  54. }
  55.  
  56. class BasicElectricityTariff extends Tariff
  57. {
  58.     private $baseCostPerMonth = 500;
  59.     protected $name = "Basic Electricity Tariff";
  60.     protected $consumptionCosts = 22;
  61.  
  62.     public function __construct(array $input)
  63.     {
  64.         $this->input = $input;
  65.         $this->setYearlyStaticExpenses($this->baseCostPerMonth);
  66.     }
  67.  
  68.     protected function setYearlyStaticExpenses($baseCostPerMonth)
  69.     {
  70.         $yearlyStaticExpenses = $baseCostPerMonth * 12;
  71.         $this->yearlyStaticExpenses = $yearlyStaticExpenses;
  72.         return $this;
  73.     }
  74.  
  75.     protected function calculate()
  76.     {
  77.         $spending = $this->input['kWhy'] * $this->getConsumptionCosts();
  78.         $total = $this->getYearlyStaticExpenses() + $spending;
  79.         return $total;
  80.     }
  81. }
  82.  
  83. class PackagedTariff extends Tariff
  84. {
  85.     private $paidLimit = 4000;
  86.     protected $yearlyStaticExpanses = 80000;
  87.     protected $name = "Packaged Tariff";
  88.     protected $consumptionCosts = 30;
  89.  
  90.     public function __construct(array $input)
  91.     {
  92.         $this->setYearlyStaticExpenses($this->yearlyStaticExpanses);
  93.     }
  94.  
  95.     protected setYearlyStaticExpenses($yearlyStaticExpanses)
  96.     {
  97.         $this->yearlyStaticExpanses = $yearlyStaticExpanses;
  98.         return $this;
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement