package cn.cn.bank.demo;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//创建一个银联接口;
//创建一个建行和一个农行卡;
//用键盘输入其卡名,判断是取钱还是查询余额或者充值要求输入6位1数字密码;
//创建一个类用来存放密码,金额;
//建行的独有功能可以贷款,并且要信誉值达到100才可贷款;但是不可以超刷;
//农行的独有功能可以超刷,充值一个11位号码的手机号码,
/*
* 总结:本次的分享主要是根据课程,学完面向对象的基础来写的;
* 主要是结合了抽象方法,继承,接口,和多态以及封装和类来写的,非常简单,可能写得重复得地方有点多,比如键盘输入
* 可以完全用传参得形式来写,因为可能不想花时间修改所以编写出来过后就没有改动了,代码显得非常的粗超,但是因为
* 简单应该都能看得懂。(这里面还可以拓展用户信息,修改密码功能等。。但是这里面我没有写因为实现起来不难就没有必要
* 因为想多花点时间学习下面的知识)
* *
* */
CCB ccb2 = new CCB(100,"21“",12);
ABC abc3 = new ABC(1000,"123456",100,"12345678901");
System.out.println(ccb2 instanceof Bank);
System.out.println( abc3 instanceof Object);
Scanner sc = new Scanner(System.in);
ccb2.v();
System.out.println("选择你要的卡,建行请按1,农行请按2");
int sun = sc.nextInt();
if(sun == 1){
Bank ccb = new CCB(1000,"123456",100);
CCB ccb1 = (CCB)ccb;
ccb1.upa(ccb);
}else if(sun == 2){
Bank abc = new ABC(1000,"123456",100,"12345678901");
ABC abc1 = (ABC)abc;
abc1.upa(abc);
}
}
}
package cn.cn.bank.demo;
public interface Bank {
void withdrawal(Bank bank);
public void deposit(Bank bank);
void card(Bank bank);
void fun(Bank bank);
void fun1(Bank bank);
}
package cn.cn.bank.demo;
public interface Video {
void v();
}
ckage cn.cn.bank.demo;
public class Method {
double money;
String psw;
int credit;
public Method(double money, String psw, int credit) {
this.money = money;
this.psw = psw;
this.credit = credit;
}
public void setMoney(double money) {
this.money = money;
}
public String getPsw() {
return psw;
}
public void setPsw(String psw) {
this.psw = psw;
}
public double getMoney() {
return money;
}
}
package cn.cn.bank.demo;
import java.util.Scanner;
public class CCB extends Method implements Bank,Video{
int count = 3;
public CCB(double money,String psw ,int credit) {
super(money,psw,credit);
}
@Override
public void withdrawal(Bank bank) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入取款金额");
double money1 = sc.nextDouble();
if(bank instanceof ABC) { //这里有问题要解决;
if((money - money1) > -2000.0){
money -= money1;
System.out.println("取款成功你取了" + money1);
// 判断 那张银行卡
bank.fun(bank);
}else {
bank.fun1(bank);
}
}else if(bank instanceof Bank){
if(money >= money1){
money -= money1;
System.out.println("取款成功你取了" + money1);
// 判断 那张银行卡
bank.fun(bank);
} else {
bank.fun1(bank);
}
}
}
//贷款
public void loans(Bank bank) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入贷款金额");
double sum2 = sc.nextDouble();
money += sum2;
System.out.println("恭喜你贷款成功,你带了" + sum2);
System.out.println("继续取钱请按1退出请按任意键");
int sum3 = sc.nextInt();
if(sum3 == 1){
withdrawal(bank);
}else {
System.out.println("退出成功");
}
}
@Override
public void card(Bank bank) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入密码");
String pasw1 = sc.next();
if(psw.equals(pasw1)){
home(bank);
}else {
String str = fo(bank);
System.out.println(str);
}
}
public String fo(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("密码输入错误你还有" + --count + "次机会" + ",继续请按1" + ",退出请按其他数字");
if(count == 0){
return "你已经没有机会了";
}
int sum = sc.nextInt();
if(sum == 1){
card(bank);
}
return "退出成功";
}
public void home(Bank bank) {
//首页
//首页里面有贷款,
Scanner sc = new Scanner(System.in);
System.out.println("取款请按1,查询余额请按2,贷款请按3,存款请按4 ,按5退出");
int sun = sc.nextInt();
if(sun == 1){
withdrawal(bank);
}else if(sun == 2){
System.out.println("你目前的余额是" + money);
}else if(sun == 3){
loans(bank);
}else if(sun == 4){
deposit(bank);
}else if(sun == 5){
System.out.println("退出成功");
}
}
@Override
public void deposit(Bank bank){//存款
Scanner sc = new Scanner(System.in);
System.out.println("请你输入存款金额");
double sc1 = sc.nextDouble();
money += sc1;
System.out.println("你充值了" + sc1 + "按1返回首页,任意键退出");
int sum1 = sc.nextInt();
if(sum1 == 1){
home(bank);
}else {
System.out.println("退出成功");
}
}
@Override
public void fun(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("你需要查询余额吗需要请按1号键" +
",退出请按2号键,继续取款请按3号键,存钱请按4号键,贷款请按5");
// }
int sum = sc.nextInt(); //查询余额 ,存钱,取款 贷款
if(sum == 1){
System.out.println("你目前的余额是" + money);
}else if(sum == 2){
home(bank);//退到首页;
}else if(sum == 3){
withdrawal(bank);
}else if(sum == 4){
deposit(bank);
}else if(sum == 5){
loans(bank);
}
}
@Override
public void fun1(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("你的余额不足可以尝试贷款(贷款请按1),查询余额请按2,继续取款请按3,返回首页请按任意键");
int sum1 = sc.nextInt();//建行贷款 ,查询余额,取款;
if (sum1 == 1) {
if (credit >= 90) {
loans(bank);
} else {
System.out.println("你的信誉极其的差不能贷款退出");//退出;
}
} else if (sum1 == 2) {
System.out.println("你目前的余额是" + money);
} else if (sum1 == 3) {
withdrawal(bank);
} else {
System.out.println("退出成功");
}
}
public void upa(Bank bank) {
if(bank instanceof ABC){
ABC bank1 = (ABC) bank;
bank1.card(bank1);
}else if(bank instanceof CCB){
CCB bank1 = (CCB) bank;
bank1.card(bank1);
}
}
@Override
public void v() {
System.out.println("你进入了银行的监控系统");
}
}
package cn.cn.bank.demo;
import java.util.Scanner;
public class ABC extends CCB{
String tbl;
public ABC(double money, String psw, int credit,String tbl) {
super(money, psw, credit);
this.tbl = tbl;
}
public void home(Bank bank) {
//首页
//首页里面有贷款,
Scanner sc = new Scanner(System.in);
System.out.println("取款请按1,查询余额请按2,充话费请按3,存款请按4 ,按5退出");
int sun = sc.nextInt();
if(sun == 1){
withdrawal(bank);
}else if(sun == 2){
System.out.println("你目前的余额是" + money);
}else if(sun == 3){
tbl1(bank);
}else if(sun == 4){
deposit(bank);
}else if(sun == 5){
System.out.println("退出成功");
}
}
public void fun(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("你需要查询余额吗需要请按1号键" +
",退出请按2号键,继续取款请按3号键,存钱请按4号键,充花费请按5");
// }
int sum = sc.nextInt(); //查询余额 ,存钱,取款 贷款
if(sum == 1){
System.out.println("你目前的余额是" + money);
}else if(sum == 2){
home(bank);//退到首页;
}else if(sum == 3){
withdrawal(bank);
}else if(sum == 4){
deposit(bank);
}else if(sum == 5){
}
}
public void fun1(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("你的余额已经超出上限,查询余额请按2,继续取款请按3,返回首页请按4");
int sum1 = sc.nextInt();//建行贷款 ,查询余额,取款;
if (sum1 == 2) {
System.out.println("你目前的余额是" + money);
} else if (sum1 == 3) {
withdrawal(bank);
} else {
home(bank);
}
}
public void tbl1(Bank bank){
Scanner sc = new Scanner(System.in);
System.out.println("请输入电话号码");
String sc1 = sc.next();
if(sc1.length() >= 11 && sc1.length() <= 12) {
System.out.println("请输入充值金额");
double num = sc.nextDouble();
System.out.println("恭喜你充值成功" + num + "元");
home(bank);
}else{
System.out.println("手机号码错误,继续充值请按1,返回首页请按2");
int sun = sc.nextInt();
if(sun == 1){
tbl1(bank);
}else if(sun == 2){
home(bank);
}
}
}
}
|
|