设计Account账户类Account账户类有以下属性
accNo //账户账号
accName //账户姓名
accPassword //账户密码
accTelno //账户手机号
accBalance //账户余额
accType //账户类型 0:储蓄账户, 1:信用账户
1. 完成类的设计,属性使用合适的数据类型;其中 账户类型 0表示储蓄账户, 1表示信用账户
class Account{constructor(accNo,accName,accPassword,accTelno,accBalance,accType) {this.accNo =accNo;this.accName =accName;this.accPassword =accPassword;this.accTelno =accTelno;this.accBalance =accBalance;this.accType =accType;}
2. 设计账户存款 depoist、取款 withdraw 两个方法,方法内部简单实现即可,需要注意方法定义的结构(参数列表、返回值)
depoist(shop){//存款this.accBalance = shop +this.accBalance;console.log("账户存入:"+this.accBalance);}withdraw(shop2){//取款if (shop2 <=this.accBalance){this.accBalance = this.accBalance -shop2;console.log("余额剩余"+this.accBalance);}if (shop2 > this.accBalance)console.log("余额不足")}
3. 创建两个银行账户对象,分别是储蓄账户与信用账户
admin(){if (this.accType ===0)this.accType ="储蓄账户";if (this.accType ===1){this.accType ="信用账户";}}}
4. 给两个账户对象信息赋值,并显示输出账户的信息
var account = new Account(1001,"张三",123456,18400000000,2000,0)account.admin()console.log(account)var account2 = new Account(1002,"李四",123457,19200000000,3000,1)account2.admin()console.log(account2)
5. 将第一个账户的手机号修改为1833893849
account.accTelno = "1888888888";console.log("手机号以替换为:"+account.accTelno)
6. 在第二个账户中进行存款1000元与取款500元,并输出账户最新余额
account2.depoist(1000)account2.withdraw(500)