package doay;
class Account6{
// 创建一个账号
String id;
// 账号id
double balance;
// 账户余额
public void save(double money){
//存钱方法
if(money > 0){
// 输入的参数 需要大于0
balance += money;
}else{
System.out.println("参数有误");
}
}
public void withdraw(double money){
if(money < 0){
System.out.println("参数有误");
} else if (money > balance) {
System.out.println("余额");
}else {
balance -= money;
}
}
}
class Customer{
// 客户类
String name;
// 姓名
String tel;
// 手机类
String cid;
// 身份证号 x 10
Account account;
// 客户的账号
}
class BankClerk {
// Customer c 客户类的对象 具体的某个人
// Account a 创建了一个账户a账户类的对象 具体的某一个账户
public void open(Customer c, Account a){ // 开户
// 客户和账号进行绑定
c.account = a;
}
}
public class Method_Exer6 {
public static void main(String[] args) {
// 创建一个客户对象
Customer c1 = new Customer();
c1.name = "周强";
c1.tel = "110";
// 电话
c1.cid = "10086";
// 身份证号
// 创建一个账户
Account a1 = new Account();
a1.id = "001";
a1.balance = 0;
// 创建一个银行对象 让他们进行绑定
BankClerk b1 = new BankClerk();
b1.open(c1, a1);
// 客户和账号进行绑定
System.out.println("客户名:" + c1.name +"; 账户id是:" + c1.account.id);
//周强取钱
c1.account.withdraw(500);
//周强存钱
c1.account.save(1000);
System.out.println(c1.account.balance);
//打印余额
//周强取钱
c1.account.withdraw(800);
System.out.println(c1.account.balance);
//打印余额
}
}
————————————————
版权声明:本文为CSDN博主「jsk_Kk」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jsk_Kk/article/details/126998733