Java怎么从银行获取到流水_java面向对象第6天 (自己做的一个较完整的银行取款机代码,对比上一期)...

package oo.day0511yue16;

import java.util.Scanner;

public class UnionPayTest {

public static void main(String[] args) {

ABCATM abcatm = new ABCATM();

// ICBCIpml icbc = new ICBCIpml(3000, "123456");//

设定g工行余额,和密码

// abcatm.insercard(icbc);

ABCIpml abc = new ABCIpml(2000, "123456"); // 设定农行余额,和密码

abcatm.insercard(abc);

abcatm.allMenu();

}

}

class ABCATM {

UnionPay card;

void insercard(UnionPay card) {

this.card = card;

;

}

public void getbalance() {

System.out.println("您的卡上余额为:" + card.getBalance());

}

public void allMenu() {

int count = 0;

int a=3;

Scanner scan = new Scanner(System.in);

System.out.println("请输入密码:");

while (count < 3) {

String str = scan.next();

if (card.checkPwd(str)) {

while (true) {

System.out.println("请选择功能:1-查询余额,2-取款,3-缴电话费,0-退卡");

int n = scan.nextInt();

if (n == 0) {

return;

}

switch (n) {

case 1:

getbalance();

break;

case 2:

drawMoney();

break;

case 3:

payTelBill();

break;

default:

System.out.println("输入信息有误");

}

}

} else {

count++;

a = 3 - count;

System.out.println("密码错误,请重新输入,还有" + a + "次机会");

}

if(a==0){

System.out.println("密码错误次数上限,请前往柜台办理");

}

}

}

public void drawMoney() {

Scanner scan = new Scanner(System.in);

System.out.println("请输入取款金额:");

double money = scan.nextDouble();

if (card.drawMoney(money)) {

System.out.println("取款成功,卡上余额为:" + card.getBalance());

} else {

System.out.println("取款失败,卡上余额不足");

}

}

public void payTelBill() {

if (card instanceof ABCIpml) {

ABCIpml abccard = (ABCIpml) card;

Scanner scan = new Scanner(System.in);

System.out.println("请输入缴费号码:");

String str = scan.next();

System.out.println("请输入缴费金额:");

double money = scan.nextDouble();

if (abccard.payTelBill(str, money)) {

System.out.println("缴费成功,卡上余额为:" + card.getBalance());

}else{

System.out.println("缴费失败,余额不足");

}

} else {

System.out.println("很抱歉,您的卡不是农业银行卡,无法完成缴费");

}

}

}

interface UnionPay { // 银联规范

double getBalance(); // 查余额

boolean checkPwd(String input);// 检查密码

boolean drawMoney(double number);// 取钱

}

class UnionIpml implements UnionPay { // 父类

protected String pwd;

protected double money;

UnionIpml(double money, String pwd) {

this.pwd = pwd;

this.money = money;

}

public double getBalance() {

return money;

}

public boolean checkPwd(String input) {

if (pwd.equals(input)) {

return true;

} else {

return false;

}

}

public boolean drawMoney(double number) {

if (money - number >= -2000) {

money -= number;

return true;

} else {

return false;

}

}

}

interface ICBC extends UnionPay { // ICBC规范,并继承银联

boolean payOnline(double number);// 在线支付

}

class ICBCIpml extends UnionIpml implements ICBC {

ICBCIpml(double money, String pwd) {

super(money, pwd);

}

public boolean payOnline(double number) {// 实现在线支付功能

if (money >= number) {

money -= number;

return true;

}

return false;

}

}

interface ABC extends UnionPay { // 农行ABC

boolean payTelBill(String telNum, double money);

}

class ABCIpml extends UnionIpml implements ABC {

ABCIpml(double money, String pwd) {

super(money, pwd);

}

public boolean payTelBill(String telNum, double money) {

if (super.money-money >= -2000) {

super.money -= money;

return true;

} else {

return false;

}

}

}

interface CCB extends UnionPay {

boolean payGas(double money);

}

class CCBIpml extends UnionIpml implements CCB {

CCBIpml(double money, String pwd) {

super(money, pwd);

}

public boolean payGas(double money) {

if (this.money > +money) {

this.money -= money;

return true;

} else {

return false;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值