From c895eb9a0e6843b4e38882f67d60ad308d5140d4 Mon Sep 17 00:00:00 2001 From: mimoyasr Date: Fri, 23 Mar 2018 11:04:44 +0200 Subject: [PATCH 1/3] oop assignment --- assignment.txt | 0 classes/Account.php | 78 ++++++++++++++++++++++++++++++++++++-- classes/AppError.php | 0 classes/Client.php | 6 +-- classes/CurrentAccount.php | 4 +- classes/SavingsAccount.php | 4 +- controllers/help.php | 14 ------- controllers/home.php | 6 --- includes.php | 3 ++ index.php | 33 +++++++++------- loader.php | 0 test-client.php | 15 -------- test-error.php | 20 ---------- 13 files changed, 105 insertions(+), 78 deletions(-) mode change 100644 => 100755 assignment.txt mode change 100644 => 100755 classes/Account.php mode change 100644 => 100755 classes/AppError.php mode change 100644 => 100755 classes/Client.php mode change 100644 => 100755 classes/CurrentAccount.php mode change 100644 => 100755 classes/SavingsAccount.php delete mode 100644 controllers/help.php delete mode 100644 controllers/home.php mode change 100644 => 100755 includes.php mode change 100644 => 100755 loader.php delete mode 100644 test-client.php delete mode 100644 test-error.php diff --git a/assignment.txt b/assignment.txt old mode 100644 new mode 100755 diff --git a/classes/Account.php b/classes/Account.php old mode 100644 new mode 100755 index 0765a40..e8f59d1 --- a/classes/Account.php +++ b/classes/Account.php @@ -1,22 +1,94 @@ _validate_account($account_number)){ AppError::show_errors(); return; } + if(!$this->_validate_balance($balance)){ + AppError::show_errors(); + return; + } $this->account_number = $account_number; + $this->balance = $balance; + } + public function Deposit($value, $log = true){ + + if(!$this->_validate_deposit($value)){ + AppError::show_errors(); + return; + } + + $this->balance += $value ; + if($log){ + $this->_add_transaction("Deposited {$value} and new balance is {$this->balance}"); + } + return $this; + } + public function Withdraw($value, $log = true){ + + if(!$this->_validate_withdraw($value)){ + AppError::show_errors(); + return; + } + + $this->balance -= $value ; + if($log){ + $this->_add_transaction("Withdraw {$value} and new balance is {$this->balance}"); + } + return $this; + } + public function Transfer($value, $to){ + + $this->Withdraw($value, false); + $to->Deposit($value, false); + $this->_add_transaction("Transfered {$value} to {$to->account_number} and new balance is {$this->balance}"); + return $this; + } + public function Balance(){ + echo "
Balanse of account {$this->account_number} is {$this->balance}
"; + return $this; + } + public function Transactions(){ + echo "
List of transactions of account {$this->account_number} :
"; + foreach ($this->transactions as $value) { + echo "{$value}
"; + } + echo "
"; + return $this; + } + protected function _add_transaction($transaction){ + $this->transactions[] = $transaction ; } - protected function _validate_account($num){ if($num >= 1000000000 && $num <= 9999999999) return true; AppError::add_error('Invalid account number'); return false; } + protected function _validate_balance($num){ + if($num >= 1000 ) return true; + + AppError::add_error('Invalid Balance'); + return false; + } + protected function _validate_deposit($num){ + if($num > 0) return true; + + AppError::add_error('Invalid Deposit'); + return false; + } + protected function _validate_withdraw($num){ + if($num > 0 && $num < $this->balance) return true; + + AppError::add_error('Invalid Withdraw '); + return false; + } } \ No newline at end of file diff --git a/classes/AppError.php b/classes/AppError.php old mode 100644 new mode 100755 diff --git a/classes/Client.php b/classes/Client.php old mode 100644 new mode 100755 index e454437..da719c5 --- a/classes/Client.php +++ b/classes/Client.php @@ -37,13 +37,13 @@ private function _validate_name($name){ return $match; } - public function add_account($account_number, $type = 'current'){ + public function add_account($account_number, $balance, $type = 'current'){ switch($type){ case 'savings': - $new_acc = new SavingsAccount($account_number); + $new_acc = new SavingsAccount($account_number , $balance); break; default: - $new_acc = new CurrentAccount($account_number); + $new_acc = new CurrentAccount($account_number, $balance); } $this->accounts[] = $new_acc; diff --git a/classes/CurrentAccount.php b/classes/CurrentAccount.php old mode 100644 new mode 100755 index e03538b..e6c2cc5 --- a/classes/CurrentAccount.php +++ b/classes/CurrentAccount.php @@ -2,8 +2,8 @@ class CurrentAccount extends Account { private $has_checks = false; - public function __construct($account_number){ - parent::__construct($account_number); + public function __construct($account_number, $balance){ + parent::__construct($account_number, $balance); } diff --git a/classes/SavingsAccount.php b/classes/SavingsAccount.php old mode 100644 new mode 100755 index 320c033..ff61023 --- a/classes/SavingsAccount.php +++ b/classes/SavingsAccount.php @@ -2,8 +2,8 @@ class SavingsAccount extends Account { private $interest = 0.0; - public function __construct($account_number){ - parent::__construct($account_number); + public function __construct($account_number, $balance){ + parent::__construct($account_number, $balance); } diff --git a/controllers/help.php b/controllers/help.php deleted file mode 100644 index aa0178d..0000000 --- a/controllers/help.php +++ /dev/null @@ -1,14 +0,0 @@ -"; - echo "Action: {$action}
"; + $client = new Client('Ahmed', 'Saeed'); + + echo $client->full_name()."
"; + + $client->add_account(1000000015, 1000)->add_checkbook(); + $client->add_account(1000000016, 1000); + $client->add_account(1000000018, 1000, 'savings')->set_interest(0.1); + + $client + ->accounts[0] + ->Deposit(1000) // make a deposit of 1000 to client's account #0 + ->Withdraw(500) // withdrawf 500 from client's account #0 + ->Transfer(200, $client->accounts[1]) // transfer 200 from client's account #0 to account #1 + ->Balance() // print balance of client's account #2 (should be 300) + ->Transactions(); // display list of transactions of client's account #0 (3 transactions) + +// echo "
";
+// 	var_dump($client);
+// echo "
"; - route($controller, $action); \ No newline at end of file diff --git a/loader.php b/loader.php old mode 100644 new mode 100755 diff --git a/test-client.php b/test-client.php deleted file mode 100644 index 7a5fc1a..0000000 --- a/test-client.php +++ /dev/null @@ -1,15 +0,0 @@ -full_name(); - //echo $client->first_name . ' ' . $client->last_name; - - $client->add_account(1000000015)->add_checkbook(); - $client->add_account(1000000016); - $client->add_account(1000000018, 'savings')->set_interest(0.1); - - var_dump($client->accounts); - diff --git a/test-error.php b/test-error.php deleted file mode 100644 index ba41c86..0000000 --- a/test-error.php +++ /dev/null @@ -1,20 +0,0 @@ -add_error('Test error 11'); - $err->add_error('Test error 12'); - - $err2->add_error('Test error 21'); - $err2->add_error('Test error 22'); - - $err->show_errors(); - - $err2->show_errors(); \ No newline at end of file From b2c496e4b4820a886d1454e185286d68c968a1b6 Mon Sep 17 00:00:00 2001 From: mimoyasr Date: Fri, 23 Mar 2018 11:07:53 +0200 Subject: [PATCH 2/3] fix .htaccess issue --- .htaccess | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .htaccess diff --git a/.htaccess b/.htaccess deleted file mode 100644 index 7ed93bd..0000000 --- a/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ -RewriteEngine On -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^(.*)$ index.php?cont=$1 [L,QSA] \ No newline at end of file From 27b125dca02c4864afafb06a1a99d7379e378f2d Mon Sep 17 00:00:00 2001 From: Amr yasser Date: Fri, 23 Mar 2018 11:09:29 +0200 Subject: [PATCH 3/3] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ec1cad4 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# php-oop +PHP OOP session 1 assignment