最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Java開發(fā)實(shí)現(xiàn)ATM系統(tǒng)

 更新時(shí)間:2022年08月12日 12:07:44   作者:LIiuxb  
這篇文章主要為大家詳細(xì)介紹了基于Java開發(fā)實(shí)現(xiàn)ATM系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

一.業(yè)務(wù)分析

通過使用Java面向?qū)ο蟮幕A(chǔ)知識(shí),開發(fā)一個(gè)ATM系統(tǒng),實(shí)現(xiàn)存款,取款,轉(zhuǎn)賬,修改密碼,注銷賬戶等功能。

二.開發(fā)準(zhǔn)備

首先,創(chuàng)建一個(gè)用戶類,為建立用戶對(duì)象做準(zhǔn)備,用戶類主要包括用戶卡號(hào)(系統(tǒng)隨機(jī)生成),用戶名,賬戶密碼,余額,取現(xiàn)額度。并搭建構(gòu)造器,以及get,set。

public class user {
? ? private String cardId ; ? ? //卡號(hào)
? ? private String username; ? ?//用戶名
? ? private String password; ? ?//密碼
? ? private double money; ? ? ? //余額
? ? private double qumoney; ? ? //取現(xiàn)額度
?
?
? ? public user(String cardId, String username, String password, ?double qumoney) {
? ? ? ? this.cardId = cardId;
? ? ? ? this.username = username;
? ? ? ? this.password = password;
? ? ? ? this.qumoney = qumoney;
? ? }
?
? ? public user() {
? ? }
?
? ? public String getCardId() {
? ? ? ? return cardId;
? ? }
?
? ? public void setCardId(String cardId) {
? ? ? ? this.cardId = cardId;
? ? }
?
? ? public String getUsername() {
? ? ? ? return username;
? ? }
?
? ? public void setUsername(String username) {
? ? ? ? this.username = username;
? ? }
?
? ? public String getPassword() {
? ? ? ? return password;
? ? }
?
? ? public void setPassword(String password) {
? ? ? ? this.password = password;
? ? }
?
? ? public double getMoney() {
? ? ? ? return money;
? ? }
?
? ? public void setMoney(double money) {
? ? ? ? this.money = money;
? ? }
?
? ? public double getQumoney() {
? ? ? ? return qumoney;
? ? }
?
? ? public void setQumoney(double qumoney) {
? ? ? ? this.qumoney = qumoney;
? ? }
}

三.創(chuàng)建測(cè)試類,寫入main方法

public class ATMSystem {
? ? public static void main(String[] args) {
? ? ? ? ArrayList<user> users = new ArrayList<>();
? ? ? ? Main(users);
? ? }

四.將主界面設(shè)置成Main方法,設(shè)計(jì)主界面,包括登錄賬戶,注冊(cè)賬戶,并且設(shè)置登錄方法,注冊(cè)方法,再調(diào)用。

public static void Main(ArrayList<user> users) {
? ? ? ? System.out.println("==========歡迎進(jìn)入xx銀行ATM系統(tǒng)==========");
? ? ? ? while (true) {
? ? ? ? ? ? System.out.println("請(qǐng)選擇操作:");
? ? ? ? ? ? System.out.println("1.登錄賬戶");
? ? ? ? ? ? System.out.println("2.注冊(cè)賬戶");
? ? ? ? ? ? Scanner sc = new Scanner(System.in);
? ? ? ? ? ? int command = sc.nextInt();
? ? ? ? ? ? switch (command) {
? ? ? ? ? ? ? ? case 1: ? ? ? ? ? ? ? ? //登錄
? ? ? ? ? ? ? ? ? ? denglu(users, sc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2: ? ? ? ? ? ? ? ? //注冊(cè)
? ? ? ? ? ? ? ? ? ? zhuce(users, sc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? System.out.println("功能不存在!");
? ? ? ? ? ? }
? ? ? ? }
? ? }

運(yùn)行結(jié)果:

五.將注冊(cè)賬戶寫成方法 

public static void zhuce(ArrayList<user> users, Scanner sc) {
? ? ? ? System.out.println("==========注冊(cè)賬戶==========");
? ? ? ? String password = "";
? ? ? ? String password2 = "";
? ? ? ? System.out.println("請(qǐng)輸入您的賬號(hào)名稱:");
? ? ? ? sc = new Scanner(System.in);
? ? ? ? String name = sc.next();
? ? ? ? while (true) {
? ? ? ? ? ? System.out.println("請(qǐng)輸入您的賬號(hào)密碼:");
? ? ? ? ? ? password = sc.next();
? ? ? ? ? ? System.out.println("請(qǐng)您再次輸入密碼:");
? ? ? ? ? ? password2 = sc.next();
? ? ? ? ? ? if (password2.equals(password)) {
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? System.out.println("兩次密碼輸入不一致!,請(qǐng)重新輸入");
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //生成卡號(hào)
? ? ? ? System.out.println("請(qǐng)輸入賬號(hào)當(dāng)次限額");
? ? ? ? double qumoney = sc.nextDouble();
? ? ? ? String cardId = kahao(users);
? ? ? ? user u1 = new user(cardId, name, password, qumoney);
? ? ? ? users.add(u1);
? ? ? ? System.out.println("恭喜開戶成功!,您的卡號(hào)是" + u1.getCardId() + ",請(qǐng)您保管");
?
? ? }

其中,涉及到生成卡號(hào),以及查詢系統(tǒng)生成的卡號(hào)是否相同,需要再寫兩個(gè)方法:

//生成卡號(hào)
? ? public static String kahao(ArrayList<user> users) {
? ? ? ? while (true) {
? ? ? ? ? ? Random rs = new Random();
? ? ? ? ? ? String cardId = "";
? ? ? ? ? ? for (int i = 0; i < 8; i++) {
? ? ? ? ? ? ? ? cardId += rs.nextInt(10);
? ? ? ? ? ? }
? ? ? ? ? ? user a = getcardId(cardId, users);
? ? ? ? ? ? if (a == null) {
? ? ? ? ? ? ? ? //無重復(fù)
? ? ? ? ? ? ? ? return cardId;
? ? ? ? ? ? }
? ? ? ? }
? ? }
//查詢卡號(hào)
? ? public static user getcardId(String kahao, ArrayList<user> users) {
? ? ? ? for (int i = 0; i < users.size(); i++) {
? ? ? ? ? ? user a = users.get(i);
? ? ? ? ? ? if (a.getCardId().equals(kahao)) {
? ? ? ? ? ? ? ? return a;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return null;
? ? }

六.將登錄賬戶寫成方法,并設(shè)計(jì)主界面

public static void denglu(ArrayList<user> users, Scanner sc) {
? ? ? ? System.out.println("==========登錄賬戶==========");
? ? ? ? if (users.size() == 0) {
? ? ? ? ? ? System.out.println("系統(tǒng)中無賬戶!請(qǐng)先注冊(cè)");
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? while (true) {
? ? ? ? ? ? System.out.println("請(qǐng)輸入您的卡號(hào):");
? ? ? ? ? ? String cardId = sc.next();
? ? ? ? ? ? String password = "";
? ? ? ? ? ? user acc = getcardId(cardId, users);
? ? ? ? ? ? if (acc != null) {
? ? ? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入您的密碼:");
? ? ? ? ? ? ? ? ? ? password = sc.next();
? ? ? ? ? ? ? ? ? ? //判斷密碼是否正確
? ? ? ? ? ? ? ? ? ? if (acc.getPassword().equals(password)) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("登錄成功!,歡迎卡號(hào)" + acc.getCardId() + "的貴賓" + acc.getUsername() + "進(jìn)入系統(tǒng)");
? ? ? ? ? ? ? ? ? ? ? ? //展示系統(tǒng)登錄后的操作界面
? ? ? ? ? ? ? ? ? ? ? ? jiemian(sc, acc, users);
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("密碼錯(cuò)誤!請(qǐng)重新輸入");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? System.out.println("不存在該卡號(hào)!");
? ? ? ? ? ? }
? ? ? ? }
? ? }

六.1編寫 展示主界面方法

public static void jiemian(Scanner sc, user acc, ArrayList<user> users) {
? ? ? ? while (true) {
? ? ? ? ? ? System.out.println("==========歡迎進(jìn)入xx銀行用戶操作界面===========");
? ? ? ? ? ? System.out.println("請(qǐng)您輸入操作命令:");
? ? ? ? ? ? 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.注銷當(dāng)前賬戶");
? ? ? ? ? ? sc = new Scanner(System.in);
? ? ? ? ? ? int commend = sc.nextInt();
? ? ? ? ? ? switch (commend) {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? atm1(acc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? atm2(acc, sc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? ? ? atm3(acc, sc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? ? ? atm4(users, acc, sc);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? ? ? atm5(acc, sc);
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? case 6:
? ? ? ? ? ? ? ? ? ? System.out.println("歡迎下次來到ATM系統(tǒng)");
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? case 7:
? ? ? ? ? ? ? ? ? ? System.out.println("是否確認(rèn)注銷賬戶?按1確認(rèn),按2取消注銷");
? ? ? ? ? ? ? ? ? ? int tf = sc.nextInt();
? ? ? ? ? ? ? ? ? ? if (tf == 1) {
? ? ? ? ? ? ? ? ? ? ? ? users.remove(acc);
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("注銷成功!");
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("取消注銷");
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? System.out.println("不存在該功能!");
? ? ? ? ? ? }
? ? ? ? }
?
? ? }

七.接下來,依次編寫各個(gè)功能的方法

//查詢功能
? ? private static void atm1(user acc) {
? ? ? ? System.out.println("========當(dāng)前賬戶詳情=========");
? ? ? ? System.out.println("卡號(hào):" + acc.getCardId());
? ? ? ? System.out.println("姓名:" + acc.getUsername());
? ? ? ? System.out.println("余額:" + acc.getMoney());
? ? ? ? System.out.println("當(dāng)次取款限額:" + acc.getQumoney());
? ? }
?
? ? //存款功能
? ? private static void atm2(user acc, Scanner sc) {
? ? ? ? System.out.println("=========存款操作=========");
? ? ? ? System.out.println("請(qǐng)您輸入存款金額:");
? ? ? ? double money = sc.nextDouble();
? ? ? ? acc.setMoney(acc.getMoney() + money);
? ? ? ? System.out.println("存款成功!");
? ? ? ? atm1(acc);
?
? ? }
?
? ? //取款
? ? private static void atm3(user acc, Scanner sc) {
? ? ? ? System.out.println("=========取款操作=========");
? ? ? ? if (acc.getMoney() < 100) {
? ? ? ? ? ? System.out.println("您的賬戶余額不足100元!無法取款");
? ? ? ? ? ? return;
? ? ? ? } else {
? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? System.out.println("請(qǐng)您輸入取款金額:");
? ? ? ? ? ? ? ? double money = sc.nextDouble();
? ? ? ? ? ? ? ? if (money > acc.getMoney()) {
? ? ? ? ? ? ? ? ? ? System.out.println("賬戶余額不足!");
? ? ? ? ? ? ? ? ? ? System.out.println("繼續(xù)取款按1,退出取款按2");
? ? ? ? ? ? ? ? ? ? int commend = sc.nextInt();
? ? ? ? ? ? ? ? ? ? switch (commend) {
? ? ? ? ? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? } else if (money > acc.getQumoney()) {
? ? ? ? ? ? ? ? ? ? System.out.println("超過了當(dāng)次取款限額!,每次最多可以取" + acc.getQumoney() + "元");
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? System.out.println("取款成功!");
? ? ? ? ? ? ? ? ? ? acc.setMoney(acc.getMoney() - money);
? ? ? ? ? ? ? ? ? ? atm1(acc);
? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
?
? ? //轉(zhuǎn)賬
? ? private static void atm4(ArrayList<user> users, user acc, Scanner sc) {
? ? ? ? System.out.println("=========轉(zhuǎn)賬操作=========");
? ? ? ? //判斷系統(tǒng)中是否有兩個(gè)以上賬戶
? ? ? ? if (users.size() < 2) {
? ? ? ? ? ? System.out.println("系統(tǒng)中無其他賬戶,不可以轉(zhuǎn)賬!");
? ? ? ? ? ? return;
? ? ? ? } else {
? ? ? ? ? ? if (acc.getMoney() == 0) {
? ? ? ? ? ? ? ? System.out.println("您的賬戶余額為0,無法轉(zhuǎn)賬");
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入對(duì)方的卡號(hào):");
? ? ? ? ? ? ? ? ? ? String dui = sc.next();
? ? ? ? ? ? ? ? ? ? user c = getcardId(dui, users);
? ? ? ? ? ? ? ? ? ? if (c != null) {
? ? ? ? ? ? ? ? ? ? ? ? //判斷賬戶對(duì)象是否為自己
? ? ? ? ? ? ? ? ? ? ? ? if (c.getCardId().equals(acc.getCardId())) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("不能給自己轉(zhuǎn)賬!");
? ? ? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? //確認(rèn)對(duì)方姓氏
? ? ? ? ? ? ? ? ? ? ? ? ? ? String name = "*" + c.getUsername().substring(1);
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)您確認(rèn)[" + name + "]的姓氏");
? ? ? ? ? ? ? ? ? ? ? ? ? ? String xingshi = sc.next();
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (c.getUsername().startsWith(xingshi)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("輸入正確!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)您輸入轉(zhuǎn)賬金額:");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? double money = sc.nextDouble();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (money > acc.getMoney()) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("余額不足!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("繼續(xù)轉(zhuǎn)賬按1,退出轉(zhuǎn)賬按2");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int commend = sc.nextInt();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? switch (commend) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? acc.setMoney(acc.getMoney() - money);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? c.setMoney(c.getMoney() + money);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("為" + c.getUsername() + "用戶" + "轉(zhuǎn)賬成功");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? atm1(acc);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("對(duì)不起,您輸入的信息有誤!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("對(duì)不起,您輸入卡號(hào)有誤!");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
?
? ? //修改密碼操作
? ? private static void atm5(user acc, Scanner sc) {
? ? ? ? System.out.println("=========修改密碼操作=========");
? ? ? ? while (true) {
? ? ? ? ? ? System.out.println("請(qǐng)輸入您的舊密碼:");
? ? ? ? ? ? String oldpassword = sc.next();
? ? ? ? ? ? String newpassword = "";
? ? ? ? ? ? if (oldpassword.equals(acc.getPassword())) {
? ? ? ? ? ? ? ? while (true) {
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入新密碼:");
? ? ? ? ? ? ? ? ? ? newpassword = sc.next();
? ? ? ? ? ? ? ? ? ? if (newpassword.equals(oldpassword)) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("新密碼不能與舊密碼重復(fù)!");
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)?jiān)俅屋斎朊艽a:");
? ? ? ? ? ? ? ? ? ? ? ? String okpassword = sc.next();
? ? ? ? ? ? ? ? ? ? ? ? if (newpassword.equals(okpassword)) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("修改密碼成功!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? acc.setPassword(newpassword);
? ? ? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("兩次密碼輸入不一致!");
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("舊密碼輸入錯(cuò)誤!");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? }
? ? }

至此,所有功能完成。

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

相關(guān)文章

最新評(píng)論

瑞金市| 资源县| 蓝山县| 宁阳县| 合阳县| 开原市| 会理县| 虞城县| 霍山县| 乐都县| 彝良县| 浠水县| 肥城市| 焦作市| 札达县| 海口市| 洮南市| 龙州县| 营口市| 惠水县| 攀枝花市| 霞浦县| 荣昌县| 大冶市| 双辽市| 大宁县| 比如县| 和林格尔县| 湛江市| 全椒县| 延边| 昌都县| 大渡口区| 简阳市| 澎湖县| 阿克苏市| 八宿县| 营山县| 五大连池市| 土默特右旗| 任丘市|