赞
踩
day14;
import java.util.Scanner;
class Account{//创建一个账号
String id;//账号id
String id2;
double balance;//账户余额
double balance2;//账户余额
public void save(double money){//存钱方法
if(money > 0){//输入的参数 需要大于0
balance += money;
}else{
System.out.println("参数有误");
}
if(money > 0){//输入的参数 需要大于0
balance2 += 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;
}
if(money <0){
System.out.println("参数有误");
}else if(money > balance2){
System.out.println("余额不足");
}else{
balance2 -= money;
}
}
}
class Customer{//客户类
String name;//姓名
String tel;//电话号
String cid;//身份证号
Account account;//客户的账户
}
class Customer2{//客户类
String name2;//姓名
String tel2;//电话号
String cid2;//身份证号
Account account2;//客户的账户
}
class BankClerk{//客户的账户
//Customer c客户类的对象 具体的某个人
//Acccount a创建了一个新账户a 账户类的对象 具体的某一个账户
public void open(Customer c, Account a){//开户
//客户和账户进行绑定 给客户c开了一个账户a
c.account = a;
}
}
class BankClerk2{
class Method_Exer6 {
public void open(Customer c2, Account a2){
c2.account = a2;
}
}
public static void main(String[] args) {
//创建客户对象
Customer c = new Customer();
c.name = "柴林燕";
c.tel = "10086";//电话
c.cid = "111111111111111111";//身份证号
Customer c2= new Customer();
c2.name = "毒狗";
c2.tel = "110";//电话
c2.cid= "001";//身份证号
//创建银行卡账号对象
Account a = new Account();
a.id = "12345678910";
a.balance = 0;
Account a2 = new Account();
a2.id = "1880000777";
a2.balance = 0;
// 创建一个银行对象 让他们进行绑定
BankClerk b = new BankClerk();
b.open(c, a);//客户进行绑定、
BankClerk b2 = new BankClerk();
b.open(c2, a2);//客户进行绑定、
System.out.println("姓名:" + c.name + ",电话:" + c.tel + ",身份证号:" + c.cid + ",账号:" + c.account.id + ",余额:" + c.account.balance);
//存款
c.account.withdraw(2000);
//存款
c.account.save(1000);
System.out.println(c.account.balance);
//取款
c.account.withdraw(2000);
System.out.println(c.account.balance);
System.out.println("姓名:" + c2.name + ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号:" + c2.account.id + ",余额:" + c2.account.balance);
c2.account.save(1000);
System.out.println(c2.account.balance);
Scanner sc=new Scanner(System.in);
System.out.println("请输入要转出的账户");
String outName= sc.next();
System.out.println("请输入要转入的账户");
String intName= sc.next();
System.out.println("请输入转账的金钱");
int maney2=sc.nextInt();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。