Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的bankSystem程序_Php_Class - Fatal编程技术网

PHP中的bankSystem程序

PHP中的bankSystem程序,php,class,Php,Class,我正试图解决这个问题,但不知道如何解决。我在PHP方面没有太多的经验。请帮帮我 创建一个类,该类保存有关客户的信息 customerAcct 客户名称 账户类型(保存/当前) 会计 平衡 将有两种类型的账户储蓄和活期存款。在储蓄账户中,每年将余额金额的5%利息添加到该客户的余额中(基于账户年龄)。而活期存款则不计息 应该有以下成员函数 getBalance():返回当前客户帐户余额 存款():接受参数金额并将其添加到该客户的余额中。金额必须大于0且不为负 setCustomerInfo()

我正试图解决这个问题,但不知道如何解决。我在PHP方面没有太多的经验。请帮帮我


创建一个类,该类保存有关客户的信息

  • customerAcct
  • 客户名称
  • 账户类型(保存/当前)
  • 会计
  • 平衡
将有两种类型的账户储蓄和活期存款。在储蓄账户中,每年将余额金额的5%利息添加到该客户的余额中(基于账户年龄)。而活期存款则不计息

应该有以下成员函数

getBalance():返回当前客户帐户余额
存款():接受参数金额并将其添加到该客户的余额中。金额必须大于0且不为负
setCustomerInfo():输入客户信息
getCustomerInfo():以表格形式显示客户信息
提取():提取成员函数将从客户帐户中提取金额,但提取金额不得大于当前余额

客户余额应在创建/开立客户账户时初始化。开户限额最低为5000美元

要运行该程序,请创建五个客户,然后创建菜单
1.添加客户信息
2。存款金额
3。提取金额
4。显示客户信息
5。检查客户余额

我就是这么做的

<!DOCTYPE html>
<html>
<body>

<?php
class BankSys {
  public $customerAcct;
  public $customerName;
  public $accountType;
  public $accountAge;
  public $balance;

  function set_Name($customerName) {
    $this->name = $customerName;
  }

  function get_Name() {
    return $this->name;
  }

  function setBalance($balance) {
    $this->balance = $balance;
  }
  function getBalance() {
    return $this->balance;
  }
}

$user1 = new BankSys();
$user1->set_Name('John');
$user1->setBalance(5000);
echo "Balance: " . $user1->getBalance();
echo "Name: " . $user1->get_Name();
?>

</body>
</html>

首先用
public
将所有内容更改为
private

private $customerAcct;
private $customerName;
private $accountType;
private $accountAge;
private $balance;
然后您需要一个具有如下set name函数的构造函数:

function __construct($name, $balance) 
    $this->set_name($name);
    $this->accountAge = 0;
    $this->accountType = 2;
    $this->customerAcct = something;

    if(empty($balance)){
        $this->balance = 5000; //Standard amount
    } else {
        //Check if $balance is an int
        $this->balance = $balance; // If you type something in 
    }
    
}

function set_name($newName) {
    //Check if that name is possible or not, then set name
    $this->name = $newName;
}
不应该有设置平衡的功能。余额只应在调用“取款”或“存款”方法时更改

function getBalance() {
    return $this->balance;
}

function withdraw($amount) {
    $this->balance = $this->getBalance() - $amount;
}

function deposit($amount) {
    if($amout <= 0){
        return;
    }

    $this->balance = $this->getBalance() + $amount;
}

创建一个html表并在单元格中执行
以显示数据。

您尝试了什么?你想让我们帮你解决什么问题?@catcon我添加了我的代码above@IhtishamKhan问题在哪里?@Mointy我在问题上方加了一条横线。问题是从这行下面开始,我现在如何向您显示我编辑的代码?@IhtishamKhan您需要的具体内容是什么?1)希望使用中的数据在表中显示。2) 想使用提款和存款功能已经使用。获取带有未捕获错误的错误:调用C:\xampp\htdocs中未定义的方法BankSys::set_name()。。。。。。。。。。。。。。
$user1 = new BankSys('John', 7000); 
$user1->withdraw(300); //Withdraw 300
$user1->deposit(300); //Deposit 300