import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class BankYW {
public static void main(String[] args) {
HashMap<Integer,Bank> bank = new HashMap<>();
Scanner sc = new Scanner(System.in);
String name;
String zh;
float ye;
//录入信息
for (int i=1;i<4;i++) {
System.out.println("请输入第"+ i +"个银行卡的姓名:");
name = sc.next();
System.out.println("请输入第"+ i +"个银行卡的账号:");
zh = sc.next();
System.out.println("请输入第"+ i +"个银行卡的余额:");
ye = sc.nextFloat();
Bank b1 = new Bank(name,zh,ye);
bank.put(i,b1);
}
//遍历
for (Map.Entry e:bank.entrySet()) {
Integer no = (Integer) e.getKey();
Bank b = (Bank) e.getValue();
System.out.println(no+" "+b.xs());
}
//取钱
System.out.println("请输入需要取钱的账户的序号:");
int xh = sc.nextInt();
System.out.println("请输入取款金额:");
float qk = sc.nextFloat();
if (bank.get(xh).qq(qk)== -1 ) {
System.out.println("取款失败:余额不足!");
}else{
System.out.println("余额:"+bank.get(xh).qq(qk));
}
}
}
class Bank {
String name;
String zh;
float ye;
public Bank(String name, String zh, float ye) {
this.name = name;
this.zh = zh;
this.ye = ye;
}
//显示信息
public String xs() {
return "姓名:"+name+" 账号:"+zh+" 余额:"+ye;
}
//取钱后的余额
public float qq(float x) {
if (ye >= x) {
if (x > 100000) {
return (float) (ye-x-(x*0.05));
}
return ye - x;
}else{
return -1;
}
}
}
08-30
08-30
08-30
08-30