bank银行项目

此为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;
	}
}
//封装

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值