您的位置:首页 > 编程语言 > Java开发

面向对象银行管理系统JAVA代码 上

2019-01-26 15:41 239 查看
               

面向对象模拟银行管理系统(java): 一般银行账户分为:借记卡账户和信用卡账户借记卡账户 DebitAccount :是指先存款后消费(或取现),没有透支功能的银行卡。 即存储卡账户,余额必须大于0。
信用卡账户 CreditAccount :信用卡是一种非现金交易付款的方式,是简单的信贷服务。在借记卡功能的基础上可以透支,但是有透支额度, 即透支只能在一定的金额范围内透支。信用额度是指银行在批准你的信用卡的时候给于你信用卡的一个最高透支的限额, 你只能在这个额度内刷卡消费,超过了这个额度就无法正常刷卡消费本程序有五个类,一个账户父类,两个子类账户(借记,信用),一个Bank类,还有一个类包含主方法详细程序代码及注释如下:
package src.day01;
public class ACC {//父类 ,以下是共有属性和方法//卡号protected static long id;// 名字protected static String name;// 身份证protected static String personId;//电子邮件protected static String email;// 密码protected static long password;//余额protected static double balance;public ACC(){
}public ACC(long id,String name,String personId,String email,long password,double balance ){ this.id = id;this.name = name;this.personId = personId;this.email = email;this.password = password;this.balance = balance;}// 存款方法public static void deposit(double money){balance += money;System.out.println("存款成功,你存入的金额为:" + money);}
public long getId() {return id;}
public void setId(long id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getPersonId() {return personId;}
public void setPersonId(String personId) {this.personId = personId;}
public String getEmail() {return email;}
public void setEmail(String email) {this.email = email;}
public long getPassword() {return password;}
public void setPassword(long password) {this.password = password;}
public double getBalance() {return balance;}
public void setBalance(double balance) {this.balance = balance;}
}package src.day01;
import java.util.*;public class Bank {//先定义 两个动态数组,其中ban用来存储借记卡数据,ba用来存储信用卡数据 static Vector ban = new Vector();static Vector ba = new Vector();//i指借记卡卡号,每增加一个用户,i自增1//j指借记卡卡号,每增加一个用户,j自增1private static long i = {{110000000:0}};private static long j = {{610000000:0}};public Bank(){
}//判断用户办理借记卡还是信用卡的相关业务public static void justy(int ch){boolean k = true ;while(k){if(ch ==1){System.out.println("你将要办理借记卡业务:");break;}else if(ch ==2){System.out.println("你将要办理信用卡业务:");break;}else{System.out.println("输入指令错误,请重新输入:");k=false;}}}//开户方法public static void register(int ch){justy(ch);Scanner re = new Scanner(System.in);System.out.println("请输入开户的用户名:");String na =re.next();long key;//两次密码不同的话循环 进行p: while (true){System.out.println("请输入密码:");long pa = re.nextLong();System.out.println("请再次输入密码:");long pa1 = re.nextLong();if(pa==pa1 ){key = pa1;break ;}else{System.out.println("两次不相同,请重新输入");continue p;}}System.out.println("请输入身份证号:");String perId = re.next();
System.out.println("请输入email地址:");String em = re.ne 4000 xt();System.out.println("请输入开户金额:");double bal = re.nextDouble();//存储和输出过程,将以上输入的正确数据存储到相应的数组中
if(ch==1){ DebitAcc De = new DebitAcc(i,na,perId,em,key,bal);ban.add(De);System.out.println("恭喜你开户成功:你的卡号为" + i);i++;}else if(ch==2){CreditAcc Cr = new CreditAcc(j,na,perId,em,key,bal);ba.add(Cr);System.out.println("恭喜你开户成功:你的卡号为" + j); j++;}System.out.println( "用户名: " + na );System.out.println("身份证:"+ perId );System.out.println("email:" +em );System.out.println("开户金额:" + bal );
}
//用户子菜单public static void MenuCu(){Scanner sc = new Scanner(System.in);while(true){System.out.println("欢迎使用银行系统");System.out.println("请输入指令:1、开户 2 、登陆 3、退出到上级"); int choice = sc.nextInt();switch(choice){case 1:openAccount();break;case 2:
logIn();break;case 3:
return;default :System .out .println("输入指令错误,请重新输入");break;}
}}//开户方法总方法private static void openAccount(){
System.out.println("你将要办理开户业务:");System.out.println("请输入你要选择的银行卡类型: 1、借记卡 2、信用卡 ");Scanner op = new Scanner(System.in);int ch = op.nextInt();register(ch);}//用户登陆总方法
public static void logIn( ){
System.out.println("欢迎进入用户登陆界面,请选择你要登陆的卡号类型: 1、借记卡 2、 信用卡" );boolean o = true;boolean p =false;Scanner lo = new Scanner(System.in);int ch = lo.nextInt();justy(ch);
l: while(o) {System.out.println("请输入你的卡号:");long user = lo. nextLong();if(ch==1){//调用对应数组的卡号群与输入卡号匹配,以下同理for(int i = 0;i<Bank.ban.size();i++){DebitAcc d = (DebitAcc)Bank.ban.get(i);if(user == d.id){System.out.println("请输入密码:");
long password = lo.nextLong();//对密码进行正误判断,正则p为true,可向下进行,false则直接返回输入卡号命令,即只有输密码一次机会p = pass(password) ;
while(p){d.menu1();
break;}}else{//卡号不存在进行的操作System.out.println("该卡号不存在,是否重新输入:1、继续2、返回上一级");int c =lo.nextInt();if(c==1){continue l;}else{return;}}}}else {for(int j =0;j<Bank.ba.size();j++){CreditAcc c = (CreditAcc)Bank.ba.get(j);if(user==c.id){System.out.println("请输入密码:");long password = lo.nextLong();p = pass(password) ;while(p){c.menu1();break;}}else{System.out.println("该卡号不存在,请重新输入:");
continue l;
}
}
}}
}//密码正误判断方法public static boolean pass( long password){if(password !=DebitAcc.password){System.out.println("密码错误!重新输入:");return false;}else{return true;}
}//管理员操作菜单public static void menuAd(){Scanner mc = new Scanner(System.in);while(true){System.out.println("欢迎使用银行系统");System.out.println("请输入指令:1、查看所有用户余额 2 、查看信用卡用户总信用额度 3、退出到上级");int m =mc.nextInt();

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: