此为bank银行项目的逐步教程
练习一:写一个账户类(Account),属性:
id:账户号码 长整数
password:账户密码
name:真实姓名
personId:身份证号码 字符串类型
email:客户的电子邮箱
balance:账户余额
方法:
deposit: 存款方法,参数是double型的金额
withdraw:取款方法,参数是double型的金额
构造方法:
有参和无参,有参构造方法用于设置必要的属性
package domain;
public class Account {
long id;//账户号码
String password;//账户密码
String name;//真实姓名
String personId;//身份证号码
String email;//客户电子邮箱
double balance;//账户余额
//无参构造
public Account() {
password="12345678";
}
//有参构造
public Account(long id,String password,String name,String personId,String email,double balance) {
this.id=id;
this.password=password;
this.name=name;
this.personId=personId;
this.email=email;
this.balance=balance;
}
//存款
public void deposit(double money) {
if(money<0) {
System.out.println("非法操作,存款金额不能小于0");
}
else {
balance+=money;
}
}
//取款
public void withdraw(double money) {
if(money<0||money>balance) {
System.out.println("非法操作,您取款的金额小于0或大于您的余额");
}
else {
balance-=money;
}
}
//封装
}