欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java實現(xiàn)基礎銀行ATM系統(tǒng)

 更新時間:2022年05月27日 11:11:16   作者:哇咔蹦  
這篇文章主要為大家詳細介紹了Java實現(xiàn)基礎銀行ATM系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java實現(xiàn)銀行ATM系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

一、前言

銀行ATM系列簡單操作

二、使用步驟

1.創(chuàng)建用戶信息類Account.java

代碼如下(示例):

package ATM;
public class Account {
? ? ? ? private String id;
? ? ? ? private String name;
? ? ? ? private double balance;
? ? ? ? private double norm;
? ? ? ? private String password;
? ? ? ? public Account() {
? ? ? ? }
? ? ? ? public Account(String id, String name, String password,double balance, double norm) {
? ? ? ? ? ? this.id = id;
? ? ? ? ? ? this.name = name;
? ? ? ? ? ? this.password=password;
? ? ? ? ? ? this.balance = balance;
? ? ? ? ? ? this.norm = norm;
? ? ? ? }
? ? ? ? public String getId() {
? ? ? ? ? ? return id;
? ? ? ? }
?
? ? ? ? public void setId(String id) {
? ? ? ? ? ? this.id = id;
? ? ? ? }
?
? ? ? ? public String getName() {
? ? ? ? ? ? return name;
? ? ? ? }
?
? ? ? ? public void setName(String name) {
? ? ? ? ? ? this.name = name;
? ? ? ? }
?
? ? ? ? public double getBalance() {
? ? ? ? ? ? return balance;
? ? ? ? }
?
? ? ? ? public void setBalance(double balance) {
? ? ? ? ? ? if(balance<0){
? ? ? ? ? ? ? ? this.balance=0;
? ? ? ? ? ? }
? ? ? ? ? ? this.balance = balance;
? ? ? ? }
?
? ? ? ? public double getNorm() {
? ? ? ? ? ? return norm;
? ? ? ? }
?
? ? ? ? public void setNorm(double norm) {
? ? ? ? ? ? if(norm<=0||norm>50000){
? ? ? ? ? ? ?this.norm=50000;
? ? ? ? ? ? }
? ? ? ? ? ? this.norm = norm;
? ? ? ? }
?
? ? ? ? public String getPassword() {
? ? ? ? ? ? return password;
? ? ? ? }
?
? ? ? ? public void setPassword(String password) {
? ? ? ? ? ? this.password = password;
? ? ? ? }
? ? ? ??
}

2.編寫用戶界面和操作功能(代碼中含有注釋)

ATMSystem.java代碼如下(示例):

package ATM;
import java.util.*;
?
public class ATMSystem {
?? ?public static void main(String[] args) {
?? ?//1.準備系統(tǒng)需要的容器對象,用于存儲賬戶對象
?? ??? ?ArrayList<Account> account=new ArrayList<>(100);
?? ??? ?//提前準備了,甄嬛用戶信息,可刪 ——自行注冊
?? ??? ?account.add(new Account("11111111","甄嬛","111",0.0, 30000));
?? ?//2.準備系統(tǒng)首頁,登錄和開戶
?? ??? ?//調(diào)用shouMain方法
?? ??? ?shouMain(account);
?? ?}
?? ?//首頁
?? ?public static void shouMain(ArrayList<Account> account){
?? ??? ?Scanner sc=new Scanner(System.in);
?? ??? ?while(true){
?? ??? ?System.out.println("=========歡迎您進入趙氏ATM系統(tǒng)=========");
?? ??? ?System.out.println("1.登錄賬戶");
?? ??? ?System.out.println("2.注冊開戶");
?? ??? ?System.out.println("請輸入命令(1、2)選擇對應操作:");
?? ??? ?String a1=sc.next();
?? ??? ?switch(a1){
?? ??? ?case "1":
?? ??? ??? ?//登錄
?? ??? ??? ?DL(account,sc);
?? ??? ??? ?break;
?? ??? ?case "2":
?? ??? ??? ?//開戶
?? ??? ??? ?ZC(account,sc);
?? ??? ??? ?break;
?? ? ? ?default:
?? ? ? ??? ?System.out.println("錯誤:命令輸入不規(guī)范!");
?? ??? ?}}
?? ?}
?? ?//開戶功能的實現(xiàn)
?? ?public static void ZC(ArrayList<Account> account,Scanner sc){
?? ??? ?System.out.println("=========用戶開戶功能=========");
?? ??? ?System.out.println("請輸入姓名:");
?? ??? ?String name=sc.next();
?? ??? ?String password="";
?? ??? ?while(true){
?? ??? ??? ?System.out.println("請設置密碼:");
?? ??? ??? ?password=sc.next();
?? ??? ??? ?System.out.println("請再輸入一次密碼:");
?? ??? ??? ?String againPassword=sc.next();
?? ??? ??? ?if(password.equals(againPassword)){
?? ??? ??? ??? ?break;
?? ??? ??? ?}else{
?? ??? ??? ??? ?System.out.println("兩次密碼不一致,請重新設置密碼!");
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("請輸入取現(xiàn)限額:");
?? ??? ?Double norm=sc.nextDouble();
?? ??? ?if(norm<=0||norm>50000){
?? ??? ??? ?norm=50000.0;
?? ??? ??? ?System.out.println("您的取現(xiàn)額度不規(guī)范,默認為50000元");
?? ??? ?}
?? ??? ?String id=ID(account);
?? ??? ?Account accounts=new Account(id,name,password,0,norm);
?? ??? ?account.add(accounts);
? ? ? ?System.out.println("您的卡號為:"+id);
?? ?}
?? ?//隨機生成八位數(shù)卡號不與已存在的卡號重復
?? ?//關鍵 ?。。。?!此方法與此方法下方的兩個方法效果一樣,任選其一
public static String ID(ArrayList<Account> account){
?? ?while(true){
?? ??? ?Random r=new Random();
?? ??? ?String id="";
?? ??? ?for(int i=0;i<1;i++){
?? ??? ??? ?int q=r.nextInt(2);
?? ??? ??? ?id+=q;
?? ??? ?}int T=0;
?? ??? ?for(int j=0;j<account.size();j++){
?? ??? ??? ?Account ac=account.get(j);?? ??? ??? ??? ?
?? ??? ??? ?if(ac.getId().equals(id)){
?? ??? ??? ??? ?T=1;
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if(T==0){
?? ??? ??? ?return id;
?? ??? ?}
?? ?}
}
//隨機生成八位數(shù)卡號不與已存在的卡號重復
//?? ?public static String ID(ArrayList<Account> account){
//?? ??? ?while(true){
//?? ??? ?Random r=new Random();
//?? ??? ?String id="";
//?? ??? ??? ?for(int i=0;i<8;i++){
//?? ??? ??? ?int q=r.nextInt(10);
// ? ? ? ? ? ? ?id+=q;
//?? ??? ?}
//?? ??? ??? ?//判斷卡號是否重復了
//?? ??? ??? ?Account ac=pdid(account,id);
//?? ??? ??? ?if(ac==null){
//?? ??? ??? ??? ?//說明當前卡號沒有重復
//?? ??? ??? ??? ?return id;
//?? ??? ??? ?}
//?? ??? ?}
//?? ?public static Account pdid(ArrayList<Account> account,String id){
//?? ??? ?int acount=0;
//?? ??? ?//如果有重復的返回重復的對象
//?? ??? ?for(int i=0;i<account.size();i++){
//?? ??? ??? ?Account ac=account.get(i);
//?? ??? ??? ?if(id.equals(ac.getId())){
//?? ??? ??? ??? ?return ac;
//?? ??? ??? ?}?? ??? ?
//?? ??? ??? ?}
//?? ??? ?return null;?? ??? ?
//?? ?}
?? ?//登錄
?? ?public static void DL(ArrayList<Account> account,Scanner sc){
?? ??? ?//調(diào)用檢查卡號的JC方法
?? ??? ?Account acc=JC(account,sc);
?? ??? ?while(true){
?? ??? ??? ?//核對輸入密碼
?? ??? ?System.out.println("請輸入密碼:");
?? ??? ?String password=sc.next();
?? ??? ?if(acc.getPassword().equals(password)){
?? ??? ??? ?//登錄后頁面//操作頁面
?? ??? ??? ?System.out.println("恭喜您,"+acc.getName()+"成功進入系統(tǒng)!");
?? ??? ??? ?showUser(account,acc,sc);
?? ??? ??? ?return;
?? ??? ?}else{
?? ??? ??? ?System.out.println("密碼錯誤!");
?? ??? ?}
?? ??? ?}
}
//檢查登錄卡號是否存在
?? ?public static Account JC(ArrayList<Account> account,Scanner sc){ ?
? ? ?? ?while(true){
? ? ?? ??? ?System.out.println("請輸入卡號:");
?? ??? ?String id=sc.next();
? ? ?? ? ? for(int i=0;i<account.size();i++){
?? ? ? ? ? Account acc=account.get(i);
?? ? ? ? if(id.equals(acc.getId())){
?? ? ? ??? ? return acc;
?? ? ? ?}}
?? ? ? ??? ?System.out.println("警告:卡號錯不存在!");
? ? ? ?}
? ? } ??
?? ?//用戶操作頁面
?? ?private static void showUser(ArrayList<Account> account,Account acc,Scanner sc) {
?? ??? ?while(true){
?? ??? ?System.out.println("====================用戶操作頁面==========================");
?? ??? ?System.out.println("1.查詢賬戶");
?? ??? ?System.out.println("2.存款");
?? ??? ?System.out.println("3.取款");
?? ??? ?System.out.println("4.轉(zhuǎn)賬");
?? ??? ?System.out.println("5.修改密碼");
?? ??? ?System.out.println("6.退出");
?? ??? ?System.out.println("7.注銷賬戶");
?? ??? ?System.out.println("請輸入命令(1、2、3、4、5、6、7)選擇對應操作:");
?? ??? ?String a2=sc.next();
?? ??? ?switch(a2){
?? ??? ?case "1"://查詢
?? ??? ??? ?CX(acc);
?? ??? ??? ?break;
?? ??? ?case "2"://存款
?? ??? ??? ?CK(acc,sc);
?? ??? ??? ?break;
?? ??? ?case "3"://取款
?? ??? ??? ?QK(acc,sc);
?? ??? ??? ?break;
?? ??? ?case "4"://轉(zhuǎn)賬
?? ??? ??? ?ZZ(account,acc,sc);
?? ??? ??? ?break;
?? ??? ?case "5"://修改密碼
?? ??? ??? ?XG(acc,sc);
?? ??? ??? ?return;
?? ??? ?case "6"://退出
?? ??? ??? ?System.out.println("歡迎下次登錄!");
?? ??? ??? ?return;
?? ??? ?case "7"://注銷
?? ??? ??? ?SC(account,acc);
?? ??? ??? ?return;
?? ? ? default:
?? ??? ? ? System.out.println("錯誤:命令輸入不規(guī)范!");
?? ??? ?}
?? ?}
? ? }
?? ?//簡單的刪除該對象
?? ?private static void SC(ArrayList<Account> account,Account acc) {
?? ??? ?account.remove(acc);
?? ??? ?return;
?? ?}
?? ?//通過Account類中set方法修改對象的密碼,可舉一反三修改取款限額
?? ?private static void XG(Account acc, Scanner sc) {
?? ??? ?while(true){
?? ??? ??? ?System.out.println("請輸入修改后的密碼:");
?? ??? ?String mima=sc.next();
?? ??? ?System.out.println("請再輸入一次:");
?? ??? ?String mm=sc.next();
?? ??? ?if(mima.equals(mm)){
?? ??? ??? ?acc.setPassword(mima);
?? ??? ??? ?System.out.println("密碼修改成功!");
?? ??? ??? ?System.out.println("請重新登錄~~");
?? ??? ??? ?return;
?? ??? ?}
?? ??? ?}?? ?
?? ?}
?? ?//轉(zhuǎn)賬有賬戶個數(shù)限制,轉(zhuǎn)賬的卡號是否存在,并核對姓名,限制轉(zhuǎn)賬金額
?? ?//通過Account類中set方法修改對象的余額
?? ?private static void ZZ(ArrayList<Account> account,Account acc, Scanner sc) {
?? ??? ?if(account.size()<2){
?? ??? ??? ?System.out.println("當前系統(tǒng),賬戶不足2個,不支持轉(zhuǎn)賬!");
?? ??? ??? ?return;
?? ??? ?}else{
?? ??? ?while(true){
?? ??? ??? ?System.out.println("請您輸入轉(zhuǎn)賬的賬戶卡號:");
?? ??? ??? ?String cards=sc.next();
?? ??? ??? ?for(int i=0;i<account.size();i++){
?? ??? ??? ? ? ? ? Account car=account.get(i);
?? ??? ??? ? ? ? if(cards.equals(car.getId())&&!cards.equals(acc.getId())){
?? ??? ??? ? ? ??? ? QR(car,sc);
?? ??? ??? ? ? ??? ? while(true){
?? ??? ??? ? ? ??? ??? ? System.out.println("請您輸入轉(zhuǎn)賬的金額:");
?? ??? ??? ? ? ??? ??? ? double money=sc.nextDouble();
?? ??? ??? ? ? ??? ??? ??? ?if(money>acc.getNorm()){
?? ??? ??? ? ? ??? ??? ??? ??? ?System.out.println("轉(zhuǎn)賬金額不能大于限額:"+acc.getNorm()+"元");
?? ??? ??? ? ? ??? ??? ??? ?}else if(money>acc.getBalance()){
?? ??? ??? ? ? ??? ??? ??? ??? ?System.out.println("您的余額為:"+acc.getBalance()+"元,不支持大額度的轉(zhuǎn)賬金額!");
?? ??? ??? ? ? ??? ??? ??? ?}else{
?? ??? ??? ? ? ??? ??? ??? ??? ?acc.setBalance(acc.getBalance()-money);
?? ??? ??? ? ? ??? ??? ??? ??? ?car.setBalance(acc.getBalance()+money);
?? ??? ??? ? ? ??? ??? ??? ??? ?System.out.println("轉(zhuǎn)賬成功,現(xiàn)在你的余額為:"+acc.getBalance());
?? ??? ??? ? ? ??? ??? ??? ??? ?break;
?? ??? ??? ? ? ??? ? }
?? ??? ??? ? ? ??? ? }
?? ??? ??? ? ? ??? ? break;
?? ??? ??? ? ? ?}else{System.out.println("警告:卡號錯,不存在!");}break; ??? ?
?? ??? ??? ?}break;
?? ??? ? ? ? ? }
?? ??? ?}
?? ?}
?? ?//確認轉(zhuǎn)賬對象的姓名,避免轉(zhuǎn)錯對象
?? ?private static void QR( Account car, Scanner sc) {
?? ??? ?String name="**"+car.getName().substring(2);
?? ??? ?while(true){
?? ??? ??? ?System.out.println("您確定要為"+name+"轉(zhuǎn)賬!");
?? ??? ?System.out.println("請您輸入對方姓名確認:");
?? ??? ?String names=sc.next();
?? ??? ?if(names.equals(car.getName())){
?? ??? ??? ?System.out.println("請繼續(xù)轉(zhuǎn)賬");
?? ??? ??? ?break;
?? ??? ?}else{
?? ??? ??? ?System.out.println("姓名不符合");
?? ??? ?}
?? ??? ?}
?? ?}
?? ?//取款是簡單的修改余額,注意取款限額
?? ?private static void QK(Account acc, Scanner sc) {
?? ??? ?while(true){
?? ??? ??? ?System.out.println("輸入您要取款的金額:");
?? ??? ?double money=sc.nextDouble();
?? ??? ?if(money>acc.getNorm()){
?? ??? ??? ?System.out.println("取款金額不能大于限額:"+acc.getNorm()+"元");
?? ??? ?}else if(money>acc.getBalance()){
?? ??? ??? ?System.out.println("您的余額為:"+acc.getBalance()+"元,不支持大額度的取款金額!");
?? ??? ?}else{
?? ??? ??? ?acc.setBalance(acc.getBalance()-money);
?? ??? ??? ?System.out.println("取款成功,現(xiàn)在你的余額為:"+acc.getBalance());
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?? ?}
?? ?//存款是簡單的修改余額
?? ?private static void CK(Account acc, Scanner sc) {
?? ??? ?System.out.println("輸入您要存款的金額:");
?? ??? ?double money=sc.nextDouble();
?? ??? ?double balance=acc.getBalance();
?? ??? ?double bal=money+balance;
?? ??? ?acc.setBalance(bal);
?? ??? ?System.out.println("存款成功~您現(xiàn)在的金額為"+bal+"元");
?? ?}
?? ?//查詢信息,通過Account類中get方法讀出想知道的數(shù)據(jù)
?? ?private static void CX(Account acc) {
?? ??? ?System.out.println("您的帳戶信息如下:");
?? ??? ?System.out.println("卡號:"+acc.getId());
?? ??? ?System.out.println("姓名:"+acc.getName());
?? ??? ?System.out.println("余額:"+acc.getBalance());
?? ??? ?System.out.println("當前取現(xiàn)額度:"+acc.getNorm());
?? ?}
?? ?
}

三、運行效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論