Facebook
From Thundering Pheasant, 2 Years ago, written in Plain Text.
This paste is a reply to Untitled from Burly Panda - view diff
Embed
Download Paste or View Raw
Hits: 143
  1. <?php
  2. class SavingAccount
  3. {
  4.         private float $balance;
  5.         private float $allDeposit;
  6.         private float $allWithdrawn;
  7.         private float $interests;
  8.         public function __construct(float $balance, float $allDeposit = 0, float $allWithdrawn = 0, float $interests = 0){
  9.                 $this->balance = $balance;
  10.                 $this->allDeposit = $allDeposit;
  11.                 $this->allWithdrawn = $allWithdrawn;
  12.                 $this->interests = $interests;
  13.         }
  14.         public function getAllDeposited(): float{
  15.                 return $this->allDeposit;
  16.         }
  17.         public function getAllWithdrawn(): float{
  18.                 return $this->allWithdrawn;
  19.         }
  20.         public function getInterests(): float{
  21.                 return $this->interests;
  22.         }
  23.         public function getBalance(): float{
  24.                 return $this->balance;
  25.         }
  26.         public function withdrawal(float $amount): void{
  27.                 $this->balance -= $amount;
  28.                 $this->allWithdrawn += $amount;
  29.         }
  30.         public function deposit(float $amount): void{
  31.                 $this->balance += $amount;
  32.                 $this->allDeposited += $amount;
  33.         }
  34.         public function addMonthlyInterest(int $interestRate): void{
  35.                 $this->balance += round($this->balance*(($interestRate/12)/100), 2);
  36.                 $this->interests += round($this->balance*($interestRate/100)/12, 2);
  37.         }
  38. }
  39. echo "";
  40. echo "\e[0;35m╔════\e[0m \e[1;35mᗷᗩᑎK ᔕᗩᐯIᑎG ᑕᗩᒪᑕᑌᒪᗩTOᖇ\e[0m \e[0;35m════\e[0m\n";
  41. echo "\e[0;35m╟–{\e[0m \e[0;32mMoney in bank acocunt:\e[0m" . "\e[0;34m";
  42. $cash = readline("") . "\e[0m";
  43. $account = new SavingAccount($cash);
  44. echo "\e[0;35m╟–{\e[0m \e[0;32mAnnual interest rate:\e[0m " . "\e[0;34m";
  45. $rate = readline("") . "\e[0m";
  46. echo "\e[0;35m╟–{\e[0m \e[0;32mMonths account opened:\e[0m " . "\e[0;34m";
  47. $monthsCount = readline("") . "\e[0m";
  48. for ($i=1; $i<=$monthsCount; $i++)
  49. {
  50.         echo "\e[0;35m╟–{\e[0m \e[0;32m{$i} month deposit:\e[0m " . "\e[0;34m";
  51.         $deposit = readline("") . "\e[0m";
  52.         if ($deposit>0){$account->deposit($deposit);}
  53.         echo "\e[0;35m╟–{\e[0m \e[0;32m{$i} month withdrawn:\e[0m " . "\e[0;34m";
  54.         $withdrawn = readline("") . "\e[0m";
  55.         if ($withdrawn>0){$account->withdrawal($withdrawn);}
  56.         $account->addMonthlyInterest($rate);
  57. }
  58. echo "\e[0;35m╠════════════════════════════════\e[0m\n";
  59. echo "\e[0;35m║\e[0m \e[0;32mTotal deposited:\e[0m \e[1;32m$" . number_format($account->getAllDeposited(), 2,  ".", ",") . "\e[0m\n";
  60. echo "\e[0;35m║\e[0m \e[0;32mTotal withdrawn:\e[0m \e[1;32m$" . number_format($account->getAllWithdrawn(), 2, ".", ",") . "\e[0m\n";
  61. echo "\e[0;35m║\e[0m \e[0;32mInterest earned:\e[0m \e[1;32m$" . number_format($account->getInterests(), 2, ".", ",") . "\e[0m\n";
  62. echo "\e[0;35m║\e[0m \e[0;32mEnding balance:\e[0m \e[1;32m$" . number_format($account->getBalance(), 2, ".", ",") . "\e[0m\n";
  63. echo "\e[0;35m╚════════════════════════════════\e[0m";