package zuoye;
import java.util.Scanner;
class Account{
String id;
String id2;
double balance;
double balance2;
public void save(double money){
if(money > 0){
balance += money;
}else{
System.out.println("参数有误");
}
if(money > 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{
public void open(Customer c, Account a){//开户
c.account = a;
}
}
class BankClerk2{
class Niubility {
public void open(Customer c2, Account a2){
c2.account = a2;
}
}
public static void main(String[] args) {
Customer c = new Customer();
c.name = "龙天";
c.tel = "7534";
c.cid = "123456789";
Customer c2= new Customer();
c2.name = "傲天邪";
c2.tel = "1367";
c2.cid= "987654321";
Account a = new Account();
a.id = "12345678910";
a.balance = 0;
Account a2 = new Account();
a2.id = "01987654321";
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(10000);
c.account.save(20000);
System.out.println(c.account.balance);
c.account.withdraw(60000);
System.out.println(c.account.balance);
System.out.println("姓名:" + c2.name + ",电话:" + c2.tel + ",身份证号:" + c2.cid + ",账号:" + c2.account.id + ",余额:" + c2.account.balance);
c2.account.save(40000);
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();
}
}
创建两个账户,两个客户,实现两个账户之间的转账
最新推荐文章于 2024-07-08 14:58:49 发布