fork download
  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3.  
  4. class CreditCalculator
  5. {
  6.  
  7. private $creditSum;
  8. private $payout;
  9.  
  10. function __construct($creditSum, $payout)
  11. {
  12. $this->creditSum = $creditSum;
  13. $this->payout = $payout;
  14. }
  15.  
  16. public function calculateCredit($creditRate, $comission, $openingPayment)
  17. {
  18. $creditSum = $this->creditSum + $openingPayment;
  19. $totalPaid = $openingPayment;
  20.  
  21. while($creditSum > 0)
  22. {
  23. $creditMonthlyPercent = ($creditSum / 100) * $creditRate;
  24. $creditSum = $creditSum + $creditMonthlyPercent + $comission;
  25.  
  26. if ($this->payout <= $creditSum)
  27. {
  28. $totalPaid += $this->payout;
  29. $creditSum -= $this->payout;
  30. }
  31. else // $this->payout > $creditSum
  32. {
  33. $totalPaid += $creditSum;
  34. $creditSum = 0;
  35. }
  36.  
  37.  
  38. } // endwhile
  39.  
  40. return round($totalPaid,2);
  41. } // calculateCredit
  42.  
  43. } // class CreditCalculator
  44.  
  45. $creditSum = 39999;
  46. $payout = 5000;
  47. $calculator = new CreditCalculator($creditSum, $payout);
  48.  
  49. $homoCreditRate = 4; // %
  50. $homoComission = 500; // roubles
  51. $homoOPayment = 0; // roubles
  52. $homoCreditTotal = $calculator->calculateCredit($homoCreditRate, $homoComission, $homoOPayment);
  53.  
  54. $softbankCreditRate = 3; // %
  55. $softbankComission = 1000; // roubles
  56. $softbankOPayment = 0; // roubles
  57. $softbankTotal = $calculator->calculateCredit($softbankCreditRate, $softbankComission, $softbankOPayment);
  58.  
  59. $strawberryCreditRate = 2; // %
  60. $strawberryComission = 0; // roubles
  61. $strawberryOPayment = 7777; // roubles
  62. $strawberryTotal = $calculator->calculateCredit($strawberryCreditRate, $strawberryComission, $strawberryOPayment);
  63.  
  64. echo '<pre>';
  65. echo "homoCredit: {$homoCreditTotal} rub. \n";
  66. echo "softbankCredit: {$softbankTotal} rub. \n";
  67. echo "strawberryCredit: {$strawberryTotal} rub. \n";
  68.  
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
<pre>homoCredit: 56423.56 rub. 
softbankCredit: 61268.72 rub. 
strawberryCredit: 61336.87 rub.