亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用Java實(shí)現(xiàn)簡(jiǎn)單ATM機(jī)功能

 更新時(shí)間:2022年01月24日 15:20:16   作者:北渺  
這篇文章主要為大家詳細(xì)介紹了用Java實(shí)現(xiàn)簡(jiǎn)單ATM機(jī)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java實(shí)現(xiàn)簡(jiǎn)單ATM機(jī)功能的具體代碼,供大家參考,具體內(nèi)容如下

項(xiàng)目介紹

基于大家使用銀行卡在ATM機(jī)取款操作,進(jìn)行相對(duì)應(yīng)ATM機(jī)操作流程的實(shí)現(xiàn)。

項(xiàng)目功能

1、注冊(cè)功能:

根據(jù)用戶輸入的賬號(hào)密碼申請(qǐng)一張銀行卡,存儲(chǔ)在銀行卡類型的數(shù)組中(一張銀行卡對(duì)應(yīng)一個(gè)有效用戶)。

2、登錄功能:

登陸失?。褐匦碌顷?或 注冊(cè)
登陸成功:對(duì)登陸的這張銀行卡可以進(jìn)行一下操作:存款、取款、查余額、轉(zhuǎn)賬、退卡功能。

項(xiàng)目知識(shí)點(diǎn)

3、java基本語(yǔ)法的使用
4、一維數(shù)組
5、函數(shù)調(diào)用,封裝
6、Java類和對(duì)象

項(xiàng)目實(shí)現(xiàn)思路

7、設(shè)計(jì)并實(shí)現(xiàn)系統(tǒng)的相關(guān)打印界面:注冊(cè)、登陸、登陸后操作
8、登錄系統(tǒng)必須輸入正確的卡號(hào)和密碼,輸入錯(cuò)誤時(shí)提示用戶重新登陸。
9、實(shí)現(xiàn)取款、存款、查余額等功能。

難點(diǎn)

對(duì)面向?qū)ο缶幊痰睦斫猓约办o態(tài)變量和實(shí)例變量的理解。
二者區(qū)別:
實(shí)例變量:跟對(duì)象有關(guān),一個(gè)對(duì)象一份實(shí)例變量
靜態(tài)變量:跟對(duì)象無(wú)關(guān),一個(gè)類一份靜態(tài)變量

源代碼

1.ATM類

public class ATM {

? ? private static boolean flag = true;
? ? private int id;
? ? private int passwd;

? ? private BankCard bankCard;

? ? private static Bank bank;
? ? /* 不寫跳1空異常*/
? ? public ATM(){
? ? ? ? bank = new Bank();
? ? }

? ? Scanner ?scanner = new Scanner(System.in);


? ? public void start(){
? ? ? ? int chioce;

? ? ? ? while (flag == true){
? ? ? ? ? ? System.out.println("請(qǐng)選擇: 1.注冊(cè) 2.登錄 3.退出");
? ? ? ? ? ? chioce = scanner.nextInt();
? ? ? ? ? ? switch(chioce){
? ? ? ? ? ? ? ? case 1:

? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入賬號(hào)和密碼:");
? ? ? ? ? ? ? ? ? ? id = scanner.nextInt();
? ? ? ? ? ? ? ? ? ? passwd = scanner.nextInt();

? ? ? ? ? ? ? ? ? ? register(id,passwd);

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:

? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入賬號(hào)和密碼:");
? ? ? ? ? ? ? ? ? ? id = scanner.nextInt();
? ? ? ? ? ? ? ? ? ? passwd = scanner.nextInt();

? ? ? ? ? ? ? ? ? ? login(id,passwd);

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:

? ? ? ? ? ? ? ? ? ? flag = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }

? ? }

? ? //注冊(cè)
? ? private void register(int id, int passwd) {

? ? ? ? //檢查此卡號(hào)是否存在
? ? ? ? if(bank.contains(id)){
? ? ? ? ? ? System.out.println("此卡號(hào)已存在,注冊(cè)失敗!");
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ? bankCard = new BankCard(id,passwd);
? ? ? ? ? ? bank.add(bankCard);
? ? ? ? ? ? System.out.println("注冊(cè)成功!");

? ? ? ? }
? ? }

? ? //登錄
? ? private void login(int id, int passwd) {

? ? ? ? //檢查此卡號(hào)是否存在
? ? ? ? if(bank.login(id,passwd)){
? ? ? ? ? ? System.out.println("登陸成功!");
? ? ? ? ? ? //登陸成功 返回卡的信息
? ? ? ? ? ? bankCard = bank.getcard(id,passwd);
? ? ? ? ? ? //調(diào)用 ATM功能函數(shù)
? ? ? ? ? ? function(bankCard);

? ? ? ? }else{
? ? ? ? ? ? System.out.println("登陸失?。?請(qǐng)重新登錄");
? ? ? ? }
? ? }

? ? //ATM功能函數(shù)
? ? private void function(BankCard bankCard) {
? ? ? ? double money;
? ? ? ? int count = 0;

? ? ? ? int chioce;
? ? ? ? while (flag == true){
? ? ? ? ? ? System.out.println("請(qǐng)選擇: 1.存款 2.取款 3.查余額 4.轉(zhuǎn)賬 ?5.退卡");
? ? ? ? ? ? chioce = scanner.nextInt();
? ? ? ? ? ? switch(chioce){
? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入存款金額:");
? ? ? ? ? ? ? ? ? ? money = scanner.nextDouble();
? ? ? ? ? ? ? ? ? ? bank.setMoney(bankCard,money);
? ? ? ? ? ? ? ? ? ? System.out.println("存款成功!");

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入取款金額:");
? ? ? ? ? ? ? ? ? ? money = scanner.nextDouble();
? ? ? ? ? ? ? ? ? ? if(bank.getMoney(bankCard,money)){
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("取款成功!");
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("余額不足取款失??!");
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 3:

? ? ? ? ? ? ? ? ? ? System.out.println("余額為:"+bank.getBalance(bankCard));

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case 4:

? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入轉(zhuǎn)賬的賬號(hào):");
? ? ? ? ? ? ? ? ? ? while(flag){
? ? ? ? ? ? ? ? ? ? ? ? count = scanner.nextInt();
? ? ? ? ? ? ? ? ? ? ? ? //檢查此卡號(hào)是否存在
? ? ? ? ? ? ? ? ? ? ? ? if(!bank.contains(count)){
? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("此卡號(hào)不存在,請(qǐng)重新輸入:");
? ? ? ? ? ? ? ? ? ? ? ? } else{
? ? ? ? ? ? ? ? ? ? ? ? ? ? flag =false;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? System.out.println("請(qǐng)輸入轉(zhuǎn)賬的金額:");
? ? ? ? ? ? ? ? ? ? money = scanner.nextDouble();
? ? ? ? ? ? ? ? ? ? if(bank.transfer(bankCard,bank.getcard1(count),money)){
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("轉(zhuǎn)賬成功!");
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? System.out.println("余額不足,轉(zhuǎn)賬失?。?);
? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? //莫名結(jié)束??
? ? ? ? ? ? ? ? case 5:

? ? ? ? ? ? ? ? ? ? flag = false;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }

? ? ? ? }

? ? }

}

2.Bank類

public class Bank {
? ? private BankCard[] cards;
? ? private static int cardsnum = 0;
// ?private static double cardsmoney = 0.0;
? ? private static final int INITSIZE = 10;

? ? public Bank(){
? ? ? ? cards = new BankCard[INITSIZE];
? ? }

? ? //查詢卡是否存在
? ? public boolean contains(int id) {
? ? ? ? for(int i=0;i<cardsnum;i++){

? ? ? ? ? ? if (cards[i].getId() == id){
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return false;
? ? }

? ? //登錄
? ? public boolean login(int id,int passwd) {
? ? ? ? for(int i=0;i<cardsnum;i++){

? ? ? ? ? ? if (cards[i].getId() == id && cards[i].getPasswd() == passwd){
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return false;
? ? }

? ? //添加一張銀行卡
? ? public void add(BankCard card) {
? ? ? ? //判斷存卡的數(shù)組是否已滿
? ? ? ? if(cards.length == cardsnum){
? ? ? ? ? ? //數(shù)組已滿執(zhí)行擴(kuò)容操作
? ? ? ? ? ? cards = Arrays.copyOf(cards,cards.length+(cards.length>>1));
? ? ? ? }

? ? ? ? //銀行卡存入銀行卡類型數(shù)組
? ? ? ? cards[cardsnum] = card;
? ? ? ? //銀行卡數(shù)+1
? ? ? ? cardsnum++;


? ? }
? ? //輸入卡號(hào),密碼返回銀行卡
? ? public BankCard getcard(int id, int passwd){

? ? ? ? for(int i=0;i<cardsnum;i++){
? ? ? ? ? ? if (cards[i].getId() == id && cards[i].getPasswd() == passwd){
? ? ? ? ? ? ? ? return cards[i];
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? return null;
? ? }

? ? //存款
? ? public boolean setMoney(BankCard card,double money){
? ? ? ? return card.setMoney(money);

? ? }

? ? //取款
? ? public boolean getMoney(BankCard card,double money){
? ? ? ? return card.getMoney(money);
? ? }

? ? //查余額
? ? public double getBalance(BankCard card){

? ? ? ? return card.getBalance();
? ? }

? ? //轉(zhuǎn)賬
? ? public boolean transfer(BankCard card, BankCard tempcard, double money){
? ? ? ? if( card.getMoney(money)){
? ? ? ? ? ? tempcard.setMoney(money);
? ? ? ? ? ? return true;
? ? ? ? }

? ? ? ? return false;
? ? }

? ? //輸入卡號(hào),密碼返回銀行卡
? ? public BankCard getcard1(int id){

? ? ? ? for(int i=0;i<cardsnum;i++){
? ? ? ? ? ? if (cards[i].getId() == id){
? ? ? ? ? ? ? ? return cards[i];
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? return null;
? ? }

}

3.BankCard類

public class BankCard {
? ? private int id;
? ? private int passwd;
? ? private double money;


? ? public BankCard(int id, int passwd) {
? ? ? ? this.id = id;
? ? ? ? this.passwd = passwd;
? ? }


? ? public int getId() {
? ? ? ? return id;
? ? }

? ? public void setId(int id) {
? ? ? ? this.id = id;
? ? }

? ? public int getPasswd() {
? ? ? ? return passwd;
? ? }

? ? public void setPasswd(int passwd) {
? ? ? ? this.passwd = passwd;
? ? }

? ? public boolean getMoney(double money) {
? ? ? ? if(this.money>=money){
? ? ? ? ? ? this.money -= money;
? ? ? ? ? ? return true;
? ? ? ? }else{
? ? ? ? ? ? return false;
? ? ? ? }
? ? }

? ? public boolean setMoney(double deposit) {
? ? ? ? this.money += deposit;
? ? ? ? return true;
? ? }

? ? public double getBalance(){
? ? ? ? return this.money;
? ? }

}

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

相關(guān)文章

  • java實(shí)現(xiàn)截取PDF指定頁(yè)并進(jìn)行圖片格式轉(zhuǎn)換功能

    java實(shí)現(xiàn)截取PDF指定頁(yè)并進(jìn)行圖片格式轉(zhuǎn)換功能

    這篇文章主要介紹了java實(shí)現(xiàn)截取PDF指定頁(yè)并進(jìn)行圖片格式轉(zhuǎn)換功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • mybatis時(shí)間范圍查詢代碼示例

    mybatis時(shí)間范圍查詢代碼示例

    這篇文章主要給大家介紹了關(guān)于mybatis時(shí)間范圍查詢的相關(guān)資料,在項(xiàng)?中避免不了要?到時(shí)間范圍查詢,文中通過(guò)代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-08-08
  • java中對(duì)象轉(zhuǎn)json字符串的幾種常用方式舉例

    java中對(duì)象轉(zhuǎn)json字符串的幾種常用方式舉例

    這篇文章主要給大家介紹了關(guān)于java中對(duì)象轉(zhuǎn)json字符串的幾種常用方式,在Java中可以使用許多庫(kù)將對(duì)象轉(zhuǎn)換為JSON字符串,其中最常用的是Jackson和Gson,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-10-10
  • Java中IO流 RandomAccessFile類實(shí)例詳解

    Java中IO流 RandomAccessFile類實(shí)例詳解

    這篇文章主要介紹了Java中IO流 RandomAccessFile類實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Spring Cloud Zuul集成Swagger實(shí)現(xiàn)過(guò)程解析

    Spring Cloud Zuul集成Swagger實(shí)現(xiàn)過(guò)程解析

    這篇文章主要介紹了Spring Cloud Zuul集成Swagger實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Java實(shí)現(xiàn)單向鏈表的基本功能詳解

    Java實(shí)現(xiàn)單向鏈表的基本功能詳解

    這篇文章主要給大家介紹了關(guān)于Java實(shí)現(xiàn)單向鏈表基本功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-03-03
  • java操作mongodb時(shí),對(duì)象bean和DBObject相互轉(zhuǎn)換的方法(推薦)

    java操作mongodb時(shí),對(duì)象bean和DBObject相互轉(zhuǎn)換的方法(推薦)

    下面小編就為大家?guī)?lái)一篇java操作mongodb時(shí),對(duì)象bean和DBObject相互轉(zhuǎn)換的方法(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-11-11
  • JVM對(duì)象創(chuàng)建和內(nèi)存分配原理解析

    JVM對(duì)象創(chuàng)建和內(nèi)存分配原理解析

    這篇文章主要介紹了JVM對(duì)象創(chuàng)建和內(nèi)存分配原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • JSON.toJSONString使用異常分析

    JSON.toJSONString使用異常分析

    這篇文章主要為大家介紹了JSON.toJSONString使用異常分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-09-09
  • Spring\SpringBoot配置連接數(shù)據(jù)庫(kù)的方法

    Spring\SpringBoot配置連接數(shù)據(jù)庫(kù)的方法

    最近在學(xué)習(xí)SpringBoot,第一步就是要配置數(shù)據(jù)庫(kù),本文詳細(xì)的介紹了Spring\SpringBoot配置連接數(shù)據(jù)庫(kù)的方法,有需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-06-06

最新評(píng)論