java学习 银行管理系统

**********************// 自己写的一个简单的银行管理系统



import java.util.Scanner;

public class 银行系统 {
******// 引入一个参数Numb来记录一个值,在所有函数中均能使用 ,这样可以大大减少代码数量。
public static void main(String[] args) {
int[] usercard = new int[5];
int[] password = new int[5];
int[] money = new int[5];
int numb = 0;
menu(usercard, password, money, numb);
}
public static void menu(int[] usercard, int[] password, int[] money,
int numb) {
System.out.println("1.注册新的银行卡号");
System.out.println("2.登录");
System.out.println("3.退出");
Scanner we = new Scanner(System.in);
int choice = we.nextInt();
switch (choice) {
case 1:
addUser(usercard, password, money, numb);
menu(usercard, password, money, numb);
break;
case 2:
loginUser(usercard, password, money, numb);
break;
case 3:
System.out.println("欢迎再次使用银行系统");
System.exit(-1);
}
}
public static void menus(int[] usercard, int[] password, int[] money,
int numb) {
System.out.println("1.存款或取款");
System.out.println("2.转账");
System.out.println("3.查询");
System.out.println("4.退出");
Scanner we = new Scanner(System.in);
int choice = we.nextInt();
switch (choice) {
case 1:
doMoney(usercard, password, money, numb);
break;
case 2:
changeMoney(usercard, password, money, numb);
break;
case 3:
check(usercard, password, money, numb);
break;
case 4:
menu(usercard, password, money, numb);
break;
}
}
// 开户(卡号+金额)
public static void addUser(int[] usercard, int[] password, int[] money,
int numb) {
for (int i = 0; i < usercard.length; i++) {
if (usercard[i] == 0) {
Scanner dad = new Scanner(System.in);
System.out.println("请输入要注册的卡号");
int userCards = dad.nextInt();
usercard[i] = userCards;
numb = i;
Scanner ad = new Scanner(System.in);
System.out.println("请输入初始化密码");
int passwords = ad.nextInt();
password[i] = passwords;
Scanner da = new Scanner(System.in);
System.out.println("请输入要存入的金额");
int moneys = da.nextInt();
money[i] = moneys;
System.out.println("开户成功");
menu(usercard, password, money, numb);
}
}
System.out.println("没有多余的新账户可用请到隔壁银行注册");
}
// 登录银行账户
public static void loginUser(int[] usercard, int[] password, int[] money,
int numb) {
for (int x = 0; x < password.length; x++) {
Scanner dads = new Scanner(System.in);
System.out.println("请输入你的银行卡密码");
int passwords = dads.nextInt();
if (password[numb] == passwords) {
System.out.println("登录成功");
menus(usercard, password, money, numb);
} else {
System.out.println("你输入的密码不正确");
continue;
}
}
}
// 取款或存款
public static void doMoney(int[] usercard, int[] password, int[] money,
int numb) {
System.out.println("1取款");
System.out.println("2存款");
Scanner ww = new Scanner(System.in);
System.out.println("请选择你要的功能");
int choice = ww.nextInt();
switch (choice) {
case 1:
Scanner dad = new Scanner(System.in);
System.out.println("请输入取款金额");
int moneys = dad.nextInt();
if (money[numb] >= moneys) {
money[numb] = money[numb] - moneys;
System.out.println("取款成功");
menus(usercard, password, money, numb);
} else {
System.out.println("余额不足");
doMoney(usercard, password, money, numb);
}
case 2:
Scanner das = new Scanner(System.in);
System.out.println("请输入存款金额");
int m = das.nextInt();
money[numb] += m;
System.out.println("存款成功");
menus(usercard, password, money, numb);
}
}
// 转账
public static void changeMoney(int[] usercard, int[] password, int[] money,
int numb) {
Scanner d = new Scanner(System.in);
System.out.println("请输入你要转账的银行卡号");
int nusercard = d.nextInt();
for (int i = 0; i < usercard.length; i++) {
if (usercard[i] == nusercard) {
Scanner dd = new Scanner(System.in);
System.out.println("请输入转账金额");
int moneyss = dd.nextInt();
money[numb] = money[numb] - moneyss;
System.out.println("转账成功");
menus(usercard, password, money, numb);
} else {
System.out.println("你输入的转账卡号不存在");
changeMoney(usercard, password, money, numb);
}
}
}
// 查询余额
public static void check(int[] usercard, int[] password, int[] money,
int numb) {
System.out.println("你的余额为" + money[numb]);
menus(usercard, password, money, numb);
}
}















你可能感兴趣的:(java学习 银行管理系统)