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

Java基于控制臺(tái)界面實(shí)現(xiàn)ATM系統(tǒng)

 更新時(shí)間:2022年05月27日 11:06:00   作者:從零開始的JAVA世界  
這篇文章主要為大家詳細(xì)介紹了Java基于控制臺(tái)界面實(shí)現(xiàn)ATM系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

這應(yīng)該算最基礎(chǔ)的Javase項(xiàng)目了,但其中邏輯還是得想想的。

功能還算完善,只是對輸入數(shù)據(jù)的校驗(yàn)沒做全,之后做web時(shí)再加上。

沒有數(shù)據(jù)庫。

完整代碼在最后。

流程圖

登錄

想模擬提款機(jī)插卡登錄的,因此沒做注冊賬號(hào)的功能,手動(dòng)先塞了三個(gè)賬號(hào)。
有三次輸入密碼機(jī)會(huì)。

查詢

取款

存款

轉(zhuǎn)賬

修改密碼

退出

代碼

文件結(jié)構(gòu)

下面兩個(gè)類復(fù)制過去放到ATM文件夾下就能運(yùn)行。

package ATM;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Account {

? ? private String cardID;
? ? private String username;
? ? private String password;
? ? private double balance;
? ? private boolean status;//卡 鎖定狀態(tài)

? ? public Account() {
? ? }

? ? public Account(String cardID, String username, String password, double balance, boolean status) {
? ? ? ? this.cardID = cardID;
? ? ? ? this.username = username;
? ? ? ? this.password = password;
? ? ? ? this.balance = balance;
? ? ? ? this.status = status;
? ? }

? ? public Account(String cardID, String username, String password, double balance) {
? ? ? ? this.cardID = cardID;
? ? ? ? this.username = username;
? ? ? ? this.password = password;
? ? ? ? this.balance = balance;
? ? }

? ? 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 getBalance() {
? ? ? ? return balance;
? ? }

? ? public void setBalance(double balance) {
? ? ? ? this.balance = balance;
? ? }

? ? public boolean isStatus() {
? ? ? ? return status;
? ? }

? ? public void setStatus(boolean status) {
? ? ? ? this.status = status;
? ? }

? ? @Override
? ? public String toString(){
? ? ? ? System.currentTimeMillis();
? ? ? ? Date date = new Date();
? ? ? ? SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
? ? ? ? String formatDate = sdf.format(date);
? ? ? ? return "銀行:新航路銀行\(zhòng)n" +
? ? ? ? ? ? ? ? "銀行賬號(hào):"+cardID+"\n"
? ? ? ? ? ? ? ? +"用戶名:"+username+"\n"
? ? ? ? ? ? ? ? +"余額:"+balance+"\n"
? ? ? ? ? ? ? ? +formatDate;
? ? }
}
package ATM;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

public class ATM {

? ? static Scanner sc = new Scanner(System.in);
? ? static ArrayList<Account> accounts;

? ? public static void main(String[] args) {

? ? ? ? //模仿插卡ATM,因此沒做注冊用戶功能,這里自己添加了幾個(gè)用戶做測試。
? ? ? ? accounts = new ArrayList<>();
? ? ? ? accounts.add(new Account("10001", "路飛", "ONEPIECE", 100,true));
? ? ? ? accounts.add(new Account("10002", "索隆", "123456", 10000,false));
? ? ? ? accounts.add(new Account("10003", "娜美", "123456", 1000000d,true));

? ? ? ? //登錄
? ? ? ? loginVerify();

? ? }

? ? //登錄驗(yàn)證
? ? public static void loginVerify() {
? ? ? ? System.out.println("提示:有這些賬戶");
? ? ? ? for (Account account : accounts) {
? ? ? ? ? ? System.out.println("卡號(hào):"+account.getCardID() +" ?用戶名:" + account.getUsername()+" ?密碼:"+account.getPassword()+" ?余額:"+account.getBalance());
? ? ? ? }
? ? ? ? System.out.println("---------------------------------------------");

? ? ? ? //模擬插卡,手動(dòng)輸入銀行卡號(hào)
? ? ? ? System.out.print("輸入銀行卡號(hào):");
? ? ? ? String cardID = sc.next();

? ? ? ? //根據(jù)卡號(hào),判斷此賬號(hào)是否存在
? ? ? ? for (int i = 0; i < accounts.size(); i++) {
? ? ? ? ? ? Account account = accounts.get(i);
? ? ? ? ? ? if (cardID.equals(account.getCardID())) { //判斷卡號(hào)是否存在
? ? ? ? ? ? ? ? if(account.isStatus()) { //看該卡是否被鎖
? ? ? ? ? ? ? ? ? ? //賬號(hào)存在,輸入密碼
? ? ? ? ? ? ? ? ? ? System.out.print("請輸入密碼:");
? ? ? ? ? ? ? ? ? ? int count = 3;//可輸入3次密碼
? ? ? ? ? ? ? ? ? ? while (count > 0) {
? ? ? ? ? ? ? ? ? ? ? ? sc.useDelimiter("\n");
? ? ? ? ? ? ? ? ? ? ? ? String pwd = sc.next();
? ? ? ? ? ? ? ? ? ? ? ? if (pwd.equals(accounts.get(i).getPassword())) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? //登錄成功,轉(zhuǎn)到主界面
? ? ? ? ? ? ? ? ? ? ? ? ? ? mainInterface(accounts.get(i));
? ? ? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? if(--count == 0){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("此卡已鎖,請到人工處咨詢辦理。");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? accounts.get(i).setStatus(false);
? ? ? ? ? ? ? ? ? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("還有" + count + "次輸入機(jī)會(huì)");
? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? System.out.println("此卡已鎖,請到人工處咨詢辦理。");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? if(i == accounts.size()-1){
? ? ? ? ? ? ? ? System.out.println("此卡號(hào)不存在!!");
? ? ? ? ? ? }
? ? ? ? }
? ? }

? ? public static void mainInterface(Account account) {

? ? ? ? System.out.println("=====================================");
? ? ? ? System.out.println("|| 1.查詢余額 ? ? ? ? ? ? ? 5.修改密碼||");
? ? ? ? System.out.println("|| 2.取款 ? ? ? ? ? ? ? ? ?6.退卡 ? ?||");
? ? ? ? System.out.println("|| 3.存款 ? ? ? ? ? ? ? ? ? ? ? ? ? ||");
? ? ? ? System.out.println("|| 4.轉(zhuǎn)賬 ? ? ? ? ? ? ? ? ? ? ? ? ? ||");
? ? ? ? System.out.println("=====================================");
? ? ? ? System.out.print("請輸入要操作的號(hào)碼:");
? ? ? ? int i = sc.nextInt();
? ? ? ? switch (i) {
? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? queryBalance(account);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? withdrawal(account);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? deposit(account);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? transfer(account);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? updatePassword(account);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case 6:
? ? ? ? ? ? ? ? exitSystem();
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? default:
? ? ? ? ? ? ? ? System.out.println("輸入號(hào)碼不對!");
? ? ? ? ? ? ? ? break;
? ? ? ? }

? ? }

? ? //查詢余額
? ? public static void queryBalance(Account account) {
? ? ? ? System.out.println("=====================================");
? ? ? ? System.out.println("|| "+account.getUsername() + "的余額: " + account.getBalance());
? ? ? ? System.out.println("=====================================");
? ? ? ? mainInterface(account);
? ? }

? ? //取款
? ? public static void withdrawal(Account account) {
? ? ? ? System.out.print("請輸入取款金額:");
? ? ? ? double money = sc.nextInt();
? ? ? ? if (money <= account.getBalance()) {
? ? ? ? ? ? account.setBalance(account.getBalance() - money);
? ? ? ? ? ? System.out.println("取款成功!!");
? ? ? ? ? ? System.out.println("=====================================");
? ? ? ? ? ? System.out.println("|| 1.返回主界面 ? ? ? ? ? ? 2.打印發(fā)票||");
? ? ? ? ? ? System.out.println("=====================================");
? ? ? ? ? ? int i = sc.nextInt();
? ? ? ? ? ? switch (i) {
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? mainInterface(account);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? Date date = new Date();
? ? ? ? ? ? ? ? ? ? SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
? ? ? ? ? ? ? ? ? ? String formatDate = sdf.format(date);
? ? ? ? ? ? ? ? ? ? System.out.println("銀行:新航路銀行\(zhòng)n"+
? ? ? ? ? ? ? ? ? ? ? ? ? ? "銀行卡:"+account.getCardID()+"\n"+
? ? ? ? ? ? ? ? ? ? ? ? ? ? "用戶名:"+account.getUsername()+"\n"+
? ? ? ? ? ? ? ? ? ? ? ? ? ? "本次取款:"+money+"\n"+
? ? ? ? ? ? ? ? ? ? ? ? ? ? formatDate);
? ? ? ? ? ? ? ? ? ? mainInterface(account);
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? } else {
? ? ? ? ? ? System.out.println("oh,我可憐的孩子!余額不足捏。");
? ? ? ? ? ? System.out.println("=====================================");
? ? ? ? ? ? System.out.println("|| 1.返回 enter ? ? ? ? ? ? ? ? ? ? ? ||");
? ? ? ? ? ? System.out.println("=====================================");
? ? ? ? ? ? sc.next();
? ? ? ? ? ? mainInterface(account);
? ? ? ? }
? ? }

? ? //存款
? ? public static void deposit(Account account) {
? ? ? ? System.out.print("請輸入要存款金額:");
? ? ? ? double tempMoney = sc.nextDouble();
? ? ? ? account.setBalance(account.getBalance() + tempMoney);
? ? ? ? System.out.println("嗶~嗶~嗶 ?點(diǎn)鈔中...");
? ? ? ? System.out.println("存款成功");
? ? ? ? mainInterface(account);
? ? }

? ? //轉(zhuǎn)賬
? ? public static void transfer(Account account) {
? ? ? ? System.out.println("請輸入對方卡號(hào)(提示賬號(hào)有:10001 /10002 /10003)");
? ? ? ? String cardID = sc.next();

? ? ? ? //根據(jù)卡號(hào),判斷此賬號(hào)是否存在
? ? ? ? for (int i = 0; i < accounts.size(); i++) {
? ? ? ? ? ? if (cardID.equals(accounts.get(i).getCardID())) {
? ? ? ? ? ? ? ? System.out.print("請輸入對象用戶名驗(yàn)證:");
? ? ? ? ? ? ? ? sc.nextLine();
? ? ? ? ? ? ? ? String next = sc.nextLine();
? ? ? ? ? ? ? ? if(next.equals(accounts.get(i).getUsername())) {
? ? ? ? ? ? ? ? ? ? System.out.print("請輸入要轉(zhuǎn)的金額:");
? ? ? ? ? ? ? ? ? ? double m = sc.nextDouble();
? ? ? ? ? ? ? ? ? ? if (m > account.getBalance()) {
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("你沒這么多錢,轉(zhuǎn)賬失??!");
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? ? ? account.setBalance(account.getBalance() - m);
? ? ? ? ? ? ? ? ? ? ? ? accounts.get(i).setBalance(m + accounts.get(i).getBalance());
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("轉(zhuǎn)賬成功");
? ? ? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? System.out.println("賬號(hào)與用戶名不匹配,轉(zhuǎn)賬失敗");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ?if(i == accounts.size()-1) {
? ? ? ? ? ? ? ?System.out.println("此卡號(hào)不存在!!");
? ? ? ? ? ?}
? ? ? ? }
? ? ? ? mainInterface(account);
? ? }

? ? //5. 修改密碼
? ? public static void updatePassword(Account account){
? ? ? ? System.out.print("請輸入新密碼:");
? ? ? ? String s1 = sc.next();
? ? ? ? System.out.print("請?jiān)俅屋斎胄旅艽a:");
? ? ? ? String s2 = sc.next();
? ? ? ? if(s1.equals(s2)){
? ? ? ? ? ? account.setPassword(s1);
? ? ? ? ? ? System.out.println("密碼修改成功,請重新登錄!");
? ? ? ? ? ? loginVerify();
? ? ? ? }else{
? ? ? ? ? ? System.out.println("兩次密碼不一致");
? ? ? ? ? ? mainInterface(account);
? ? ? ? }
? ? }

? ? //6. 退出
? ? public static void exitSystem() {

? ? ? ? System.exit(0);
? ? ? ? //loginVerify();
? ? }
}

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

相關(guān)文章

  • Jackson多態(tài)序列化圖文詳解

    Jackson多態(tài)序列化圖文詳解

    jackson允許配置多態(tài)類型處理,當(dāng)進(jìn)行反序列話時(shí),JSON數(shù)據(jù)匹配的對象可能有多個(gè)子類型,為了正確的讀取對象的類型,我們需要添加一些類型信息,下面這篇文章主要給大家介紹了關(guān)于Jackson多態(tài)序列化的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • 一文帶你看懂SpringBoot中的全局配置文件

    一文帶你看懂SpringBoot中的全局配置文件

    這篇文章主要介紹了一文帶你看懂SpringBoot中的全局配置文件,全局配置文件能夠?qū)σ恍┠J(rèn)配置值進(jìn)行修改,Spring Boot使用一個(gè)application.properties或者application.yaml的文件作為全局配置文件,需要的朋友可以參考下
    2023-08-08
  • java 將 list 字符串用逗號(hào)隔開拼接字符串的多種方法

    java 將 list 字符串用逗號(hào)隔開拼接字符串的多種方法

    這篇文章主要介紹了java 將 list 字符串用逗號(hào)隔開拼接字符串,本文給大家分享四種方法,每種方法通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • MyBatisPlus?大數(shù)據(jù)量查詢慢的問題解決

    MyBatisPlus?大數(shù)據(jù)量查詢慢的問題解決

    本文主要介紹了MyBatis?Plus?解決大數(shù)據(jù)量查詢慢問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • 詳解SpringBoot 多線程處理任務(wù) 無法@Autowired注入bean問題解決

    詳解SpringBoot 多線程處理任務(wù) 無法@Autowired注入bean問題解決

    這篇文章主要介紹了詳解SpringBoot 多線程處理任務(wù) 無法@Autowired注入bean問題解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-06-06
  • Spring Boot如何使用Undertow代替Tomcat

    Spring Boot如何使用Undertow代替Tomcat

    這篇文章主要介紹了Spring Boot如何使用Undertow代替Tomcat,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Java System類用法實(shí)戰(zhàn)案例

    Java System類用法實(shí)戰(zhàn)案例

    這篇文章主要介紹了Java System類用法,結(jié)合具體實(shí)例形式分析了java使用System類獲取系統(tǒng)環(huán)境變量信息相關(guān)操作技巧,需要的朋友可以參考下
    2019-07-07
  • 深入理解java long 存儲(chǔ)時(shí)間戳

    深入理解java long 存儲(chǔ)時(shí)間戳

    存儲(chǔ)時(shí)間打算用時(shí)間戳來存儲(chǔ),打算用long類型來代表時(shí)間戳,這篇文章主要介紹了深入理解java long 存儲(chǔ)時(shí)間戳,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2018-10-10
  • Java實(shí)現(xiàn)微信發(fā)紅包

    Java實(shí)現(xiàn)微信發(fā)紅包

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)微信發(fā)紅包,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • java仿QQ微信聊天室功能的實(shí)現(xiàn)

    java仿QQ微信聊天室功能的實(shí)現(xiàn)

    這篇文章主要介紹了java仿QQ微信聊天室的實(shí)現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,,需要的朋友可以參考下
    2021-04-04

最新評論

东兰县| 宾川县| 宝清县| 苍南县| 岐山县| 福安市| 美姑县| 富锦市| 平江县| 资阳市| 昭觉县| 延边| 苏尼特左旗| 手游| 城步| 会理县| 万盛区| 新兴县| 新野县| 浙江省| 沁水县| 油尖旺区| 仲巴县| 长垣县| 响水县| 磴口县| 岐山县| 望江县| 黑水县| 满洲里市| 纳雍县| 介休市| 綦江县| 天水市| 六盘水市| 北安市| 十堰市| 南江县| 弥渡县| 内丘县| 满城县|