Java:银行账户类

class Untitled {
	public static void main(String[] args) {
		Customer tom=new Customer("tom","1000",2000,0.05);
		
		tom.Ac.deposit(2000);
	}
}

class Customer{//用户类
	
	private String name;//姓名
	Account Ac;//账户
	
	public Customer(){}//缺省构造
	
	public Customer(String name,String iD,double balance,double annualInterestRate){
		this.name = name;
		this.Ac = new Account(iD,balance,annualInterestRate);//账户对象属性初始化
	}
}


class Account{//账户类
	
	private String iD;//账户iD
	private double balance;//余额
	private double annualInterestRate;//年利率
	
	public Account(){}//缺省构造
	
	public Account(String iD,double balance,double annualInterestRate){
		this.iD = iD;
		this.balance = balance;
		this.annualInterestRate = annualInterestRate;
	}
	
	public void setiD(String iD){//设置iD
		this.iD=iD;
	}
	public void getiD(){
		System.out.println("iD:"+this.iD);//查看iD
	}
	
	public void setbalance(double balance){//设置账户金额
		this.balance=balance;
	}
	public void getbalance(){
		System.out.println("balance:"+this.balance);//查看账户金额
	}
	
	public void setannualInterestRate(double annualInterestRate){//设置年利率
		this.annualInterestRate = annualInterestRate;
	}
	public void getannualInterestRate(){
		System.out.println("annualInterestRate:"+this.annualInterestRate);//查看年利率
	}
	
	public void deposit(double demoney){//存款
		this.balance += demoney;
		System.out.println("存款成功,当前余额为:"+this.balance);
	}
	
	public void withdraw(double wdmoney){//取款
		if(this.balance >= wdmoney){
			this.balance -= wdmoney;
			System.out.println("取款成功,当前余额为:"+this.balance);
		}
		else{
			System.out.println("余额不足,取款失败");
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值