「java编写模拟银行」java制作银行系统
本篇文章给大家谈谈java编写模拟银行,以及java制作银行系统对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、Java课程设计,模拟银行存取业务,按照这个流程图去做,其实最主要的是求画圈的部分怎么写和它的方法。
- 2、JAVA编写银行账户操作模拟
- 3、JAVA编写银行账户程序摸拟银行账户的存\取款操作
- 4、用java编写模拟网上银行登录及存取款业务
Java课程设计,模拟银行存取业务,按照这个流程图去做,其实最主要的是求画圈的部分怎么写和它的方法。
请点击输入图片描述
package com.greatwall.business.controller;
import java.math.BigDecimal;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author xysddjyt
* @since 2020/6/16 15:06
*/
public class BankTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// 余额(单位:分)
Long BALANCE = 10000000L;
// 卡号
String card = "001";
// 密码
String password = "123456";
String inputCard = new String();
String inputPassword = new String();
String quit = new String();
while (true) {
System.out.println("\n欢迎来到网上银行办理存取款业务!");
System.out.println("请输入银行卡号和银行卡密码进行登录!");
while (true) {
System.out.print("请输入银行卡号(按q退出): ");
inputCard = scan.nextLine();
quit = inputCard;
if (inputCard.equals("q")) {
break;
}
if (!inputCard.equals(card)) {
System.out.print("您输入银行卡号不正确,请重新输入 ");
continue;
}
break;
}
if (quit.equals("q")) {
continue;
}
while (true) {
System.out.print("请输入银行卡密码(按q退出): ");
inputPassword = scan.nextLine();
quit = inputPassword;
if (inputPassword.equals("q")) {
break;
}
if (!inputPassword.equals(password)) {
System.out.print("您输入银行卡密码不正确,请重新输入 ");
continue;
}
break;
}
if (quit.equals("q")) {
continue;
}
System.out.print("登录成功,当前登录的账户名:" + inputCard);
String type = "4";
while (!type.equals("0")) {
System.out.print("\n您当前的余额为:" + money(BALANCE) + "元");
System.out.print("\n请选择操作类型。(存款:1;取款:2 ;余额:3;退出:0)\n");
type = scan.nextLine();
switch (type) {
case "1": {
System.out.print("请输入您的存款金额(元):");
String chageNumber = scan.nextLine();
if (!isPositiveInteger(chageNumber)) {
System.out.print("请输入正确的存款金额!");
continue;
}
BALANCE = Long.valueOf(chageNumber) * 100 + BALANCE;
continue;
}
case "2": {
System.out.print("请输入您的取款金额(元):");
String chageNumber = scan.nextLine();
if (!isPositiveInteger(chageNumber)) {
System.out.print("请输入正确取款金额!");
continue;
}
BALANCE = BALANCE - Long.valueOf(chageNumber) * 100;
continue;
}
case "3": {
System.out.print("您当前的余额为:" + money(BALANCE) + "元\n");
continue;
}
default: {
continue;
}
}
}
}
}
private static boolean isMatch(String regex, String orginal) {
if (orginal == null || orginal.trim().equals("")) {
return false;
}
Pattern pattern = Pattern.compile(regex);
Matcher isNum = pattern.matcher(orginal);
return isNum.matches();
}
// 判断数据是否为正整数
public static boolean isPositiveInteger(String orginal) {
return isMatch("^\\+{0,1}[1-9]\\d*", orginal);
}
// 分转元,转换为bigDecimal在toString
public static String money(Long money) {
return BigDecimal.valueOf(money).divide(new BigDecimal(100)).toString();
}
}
JAVA编写银行账户操作模拟
这个很简单,你只是要设计对吧?如果你不实现GUI的话,就可以用字符输入来公职系统,一个main方法,监听着用户输入,1存款、2取款、3查询余额、4显示账号.用户输入什么数字进入到相应的方法。每个方法可以用jdbc直接访问oracle。
但是,个人建议,做个GUI没什么难的,这个BS结构的比较合适。不知道你的jsp+js+css等学的如何,如果可以的话可以用spring+struts+ibitis来做,很简单,估计1天就弄好了。
有什么不懂可以追问
望采纳
JAVA编写银行账户程序摸拟银行账户的存\取款操作
public class ATM {
public static void main(String[] args) {
// 开立帐号
Account account = new Account();
// 在 account 中存 10,000 元
account.setBalance(10000);
// 检查 account 中的存款
System.out.println("帐户原始金额 : " + account.getBalance() + " 元");
// 小明, 小华与小英一起对 account 进行提款的动作
WithDraw s1 = new WithDraw("小明", account, 5000); // 小明 在 account 中提 5000 元
WithDraw s2 = new WithDraw("小华", account, 2000); // 小华 在 account 中提 2000 元
WithDraw s3 = new WithDraw("小英", account, 4000); // 小英 在 account 中提 4000 元
s1.start();
s2.start();
s3.start();
}
}
//帐户
class Account {
private int balance; // 帐户馀额
public int getBalance() { // 取得帐户馀额
return balance;
}
public void setBalance(int money) { // 设定帐户馀额
balance = money;
}
// 提款方法
public void withDraw(Account account, int withdrawMoney) {
String tName = Thread.currentThread().getName(); // tName=提款人
System.out.println(tName + " 开始提款 ... ");
boolean withDrawStatus; // 提款状态 说明:false=提款失败, true=提款成功
synchronized(ATM.class) {
int tmpBalabce = account.getBalance(); // 取得最新帐户馀额
//用 for-loop 模拟提款时系统所花的时间
for(double delay=0;delay99999999;delay++) {
// ... 提款进行中 ...
}
tmpBalabce = tmpBalabce - withdrawMoney; // 最新帐户馀额 - 欲提款金额 (用来判断是否馀额足够的依据)
if (tmpBalabce 0) { // 判断是否馀额足够
withDrawStatus = false;
System.out.println("....................");
System.out.println(" 帐户馀额不足!");
System.out.println("....................");
} else {
withDrawStatus = true;
account.setBalance(tmpBalabce); // 回存account最後剩馀金额
}
}
System.out.println(tName + "的交易单:");
System.out.println("\t欲提款金额:" + withdrawMoney + "元");
System.out.println("\t帐户馀额:" + account.getBalance());
if(withDrawStatus == true){
System.out.println(tName + " 完成提款 ... ");
} else {
System.out.println(tName + " 提款失败 ... ");
}
System.out.println("-------------------------------");
}
}
// 提款类别
class WithDraw extends Thread {
private Account account; // 帐号
private int withdrawMoney; // 欲提款的金额
// tName:执行绪名称, account:Account物件名称, withdrawMoney:欲提款金额
public WithDraw(String tName, Account account, int withdrawMoney) {
setName(tName);
this.account = account;
this.withdrawMoney= withdrawMoney;
}
public void run() {
// 执行提款动作(account:帐号, withdrawMoney 欲提款金额)
account.withDraw(account, withdrawMoney); // 执行提款动作
}
}
用java编写模拟网上银行登录及存取款业务
public class Account {
protected String accId;
protected String name;
protected double money;
public Account (String accId,String name){
this(accId,name,0);
}
public Account (String accId,String name,double money){
this.accId = accId;
this.name = name;
this.money = money;
}
public void saveMoney(double money){
if(money = 0){
System.out.println("存款金额必须大于0");
}
this.money += money;
System.out.println("存款成功");
}
public double getMoney(double money){
if(money = 0){
System.out.println("取款金额必须大于0");
return 0;
}
if(this.money = money){
System.out.println("余额不足,无法取款");
return 0;
}
this.money -= money;
System.out.println("取款成功");
return money;
}
public double getBalance(){
return this.money;
}
protected double getOverdraft(){
return 0;
}
// 实现了equals方法,list比较时才能正确
@Override
public boolean equals(Object obj) {
if(obj == null){
return false;
}
if(this == obj){
return true;
}
if(obj instanceof Account){
return this.accId.equals(((Account)obj).accId);
}
return false;
}
@Override
public String toString() {
return "账户=" + accId + ",名字=" + name + ",余额=" + money;
}
}
public class Bank {
// Account实现了equals方法,list查找时才能正确
private ListAccount usersAccounts;
public Bank() {
usersAccounts = new ArrayListAccount();
}
public void addAccount(Account account) {
if (usersAccounts.contains(account)) {
System.out.println("添加失败,不能添加同样的账户");
return;
}
usersAccounts.add(account);
}
public boolean delAccount(Account account) {
return usersAccounts.remove(account);
}
public boolean delAccount(String accId) {
return delAccount(new Account(accId, null));
}
public boolean existAccount(Account account) {
return usersAccounts.contains(account);
}
public boolean existAccount(String accId) {
return existAccount(new Account(accId, null));
}
public Account getAccount(String accId){
return usersAccounts.get(usersAccounts.indexOf(new Account(accId, null)));
}
public double getAllMoney() {
// 不考虑是否溢出,只是把所有用户余额相加
double result = 0;
for (Account account : usersAccounts) {
result += account.getBalance();
}
return result;
}
public double getAllOverdraft() {
// 不考虑是否溢出
double result = 0;
for (Account account : usersAccounts) {
result += account.getOverdraft();
}
return result;
}
public int getAccountNum() {
return usersAccounts.size();
}
public int getCreditAccountNum() {
int num = 0;
for (Account account : usersAccounts) {
// instanceof 性能没有简单的方法快。
if (account instanceof CreditAccount) {
num++;
}
}
return num;
}
public int getSavingAccountNum() {
int num = 0;
for (Account account : usersAccounts) {
if (account instanceof SavingAccount) {
num++;
}
}
return num;
}
public ListAccount getAllAccount() {
return usersAccounts;
}
}
public class CreditAccount extends Account{
private double overdraft;
public CreditAccount(String accId,String name){
super(accId, name);
this.overdraft = 1000;
}
public CreditAccount(String accId,String name,double money){
this(accId, name,money,1000);
}
public CreditAccount(String accId,String name,double money,double overdraft){
super(accId, name,money);
this.overdraft = overdraft;
}
@Override
public double getMoney(double money) {
if(money = 0){
System.out.println("取款金额必须大于0");
return 0;
}
if(this.money + overdraft = money){
System.out.println("余额不足,无法取款");
return 0;
}
this.money -= money;
System.out.println("取款成功");
return money;
}
@Override
public double getOverdraft(){
return overdraft;
}
@Override
public String toString() {
return "账户=" + accId + ",名字=" + name + ",余额=" + money + ",透支=" + overdraft;
}
}
public class SavingAccount extends Account {
public SavingAccount(String accId, String name) {
super(accId, name);
}
public SavingAccount(String accId, String name, double money) {
super(accId, name, money);
}
@Override
public double getMoney(double money) {
return super.getMoney(money);
}
@Override
public double getOverdraft() {
return super.getOverdraft();
}
}
public class Test {
private static Bank bank = new Bank();
public static void main(String[] args) {
Test.genAccount();
// 开户
Account a1 = new CreditAccount("1", "1", 200, 2000);
Account a2 = new SavingAccount("2", "2", 300);
Account a3 = new SavingAccount("3", "3", 400);
Account a4 = new CreditAccount("4", "4", 500, 2000);
Account a5 = new CreditAccount("4", "5", 600, 2000); // 帐号4重
bank.addAccount(a1);
bank.addAccount(a2);
bank.addAccount(a3);
bank.addAccount(a4);
bank.addAccount(a5);
showNowAccount();
// 销户
bank.delAccount("1");
bank.delAccount("2");
showNowAccount();
// 存款
if(bank.existAccount("3")){
Account acc = bank.getAccount("3");
acc.saveMoney(100);
}
showNowAccount();
// 取款
if(bank.existAccount("3")){
Account acc = bank.getAccount("3");
System.out.println("余额=" + acc.getBalance());
acc.getMoney(100);
System.out.println("余额=" + acc.getBalance());
acc.getMoney(1000);
System.out.println("余额=" + acc.getBalance());
}
if(bank.existAccount("4")){
Account acc = bank.getAccount("4");
System.out.println("余额=" + acc.getBalance());
acc.getMoney(100);
System.out.println("余额=" + acc.getBalance());
acc.getMoney(1000);
System.out.println("余额=" + acc.getBalance());
acc.getMoney(10000);
System.out.println("余额=" + acc.getBalance());
}
System.out.println(bank.getAccountNum());
System.out.println(bank.getAllMoney());
System.out.println(bank.getAllOverdraft());
System.out.println(bank.getCreditAccountNum());
System.out.println(bank.getSavingAccountNum());
}
public static void genAccount(){
String s = "1000 0000 0000 000";
Account a = null;
for(int i = 1; i 11; i ++){
if((i 2) == 0){
a = new CreditAccount(s + String.valueOf(i), "账户" + String.valueOf(i));
} else {
a = new SavingAccount(s + String.valueOf(i), "账户" + String.valueOf(i));
}
bank.addAccount(a);
}
}
public static void showNowAccount(){
for(Account account : bank.getAllAccount()){
System.out.println(account);
}
}
}
// 面向对象,看多写多了就会了,简单的随便写的,有错误先不用太纠结。
java编写模拟银行的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java制作银行系统、java编写模拟银行的信息别忘了在本站进行查找喔。
发布于:2022-11-21,除非注明,否则均为
原创文章,转载请注明出处。