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

Java實(shí)現(xiàn)簡(jiǎn)單銀行ATM功能

 更新時(shí)間:2020年10月27日 17:09:35   作者:小黑來(lái)修仙  
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)銀行ATM簡(jiǎn)單功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

實(shí)現(xiàn)功能

1、用戶需要通過(guò)輸入銀行卡號(hào)和密碼才能進(jìn)入ATM系統(tǒng)
2、用戶可以在ATM中實(shí)現(xiàn)取款、存款、轉(zhuǎn)賬、余額查詢、退出系統(tǒng)等功能

簡(jiǎn)單分析

1、創(chuàng)建User類(cardNo,identity,phone,username,password,balance(余額))
2、創(chuàng)建Bank類,主要實(shí)現(xiàn)初始化用戶、用戶登錄、顯示菜單、取款、存款、轉(zhuǎn)賬、余額查詢、退出系統(tǒng)等功能。

代碼實(shí)現(xiàn)

User.java

public class User {
  private String username;
  private int password;
  private String cardNo;
  private String identity;
  private String phone;
  private double blance;

 public User() {
 }

 public User(String username, int password, String cardNo, String identity, String phone, double blance) {
  this.username = username;
  this.password = password;
  this.cardNo = cardNo;
  this.identity = identity;
  this.phone = phone;
  this.blance = blance;
 }

 public String getUsername() {
  return username;
 }

 public void setUsername(String username) {
  this.username = username;
 }

 public int getPassword() {
  return password;
 }

 public void setPassword(int password) {
  this.password = password;
 }

 public String getCardNo() {
  return cardNo;
 }

 public void setCardNo(String cardNo) {
  this.cardNo = cardNo;
 }

 public String getIdentity() {
  return identity;
 }

 public void setIdentity(String identity) {
  this.identity = identity;
 }

 public String getPhone() {
  return phone;
 }

 public void setPhone(String phone) {
  this.phone = phone;
 }

 public double getBlance() {
  return blance;
 }

 public void setBlance(double blance) {
  this.blance = blance;
 }
}

Bank.java

public class Bank {
 //創(chuàng)建用戶數(shù)組
 private User[] users=new User[100];
 //用戶個(gè)數(shù)
 private int size=0;
 //當(dāng)前登錄的用戶
 private User loginuser;

 public Bank() {
  initial();//初始化用戶
 }

 /**
 * 初始化用戶
 */
 public void initial(){
  User user1=new User("鐘愛(ài)",12346,"6226789234023434","130324192309123074","13133565435",2312313);
  User user2=new User("冷冬",12354,"6226789234023567","1305472309123074","13446745675",2333);
  User user3=new User("小龍",9893,"6226789234023564","13032414575467457","13145745435",255553);
  User user4=new User("趙麗穎",6342,"6226789234029324","130324192647456774","13145675435",288883);
  User user5=new User("徐三哥",8445,"6226789234025487","1303241923456744","1457785435",28989);
  users[0]=user1;
  users[1]=user2;
  users[2]=user3;
  users[3]=user4;
  users[4]=user5;
  size=5;
 }
 /**
 * 用戶登錄
 */
 public User login(String cardNo,int password){
  for (int i = 0; i <size ; i++) {
 if((users[i].getCardNo().equals(cardNo))&&(users[i].getPassword()==password)){
    loginuser=users[i];
    return users[i];
   }
  }
  return null;
 }
 /**
 * 顯示菜單
 */
 public void showMenus(){
  Scanner input =new Scanner(System.in);
  do { System.out.println("**********************************歡迎進(jìn)入ATM系統(tǒng)*****************************************");
  System.out.println("*********************1 存款 2 取錢 3 轉(zhuǎn)賬 4 查詢余額 5 修改密碼 0 退出***********************");


   int choice=input.nextInt();
   switch (choice){
    case 1:
     //取款
     save();
     break;
    case 2:
     //存錢
     withdraw();
     break;
    case 3:
     //轉(zhuǎn)賬
     trans();
     break;
    case 4:
     //查詢余額
     query();
     break;
    case 5:
     //修改密碼
     revise();
     break;
    case 0:
     //退出ATM系統(tǒng)
     System.out.println("歡迎下次使用本系統(tǒng)");
     return;
   }
  } while (true);
 }
 /**
  * 存款操作
  */
 public void save(){
  System.out.println("請(qǐng)輸入您的存款金額:");
  Scanner input=new Scanner(System.in);
  int money=input.nextInt();
  if(loginuser!=null){
   if(money>0){
    loginuser.setBlance(loginuser.getBlance()+money);
    System.out.println("存款成功");
    System.out.println("您的當(dāng)前余額為"+loginuser.getBlance());
   }else{
    System.out.println("輸入錯(cuò)誤!");
   }
  }else{
   System.out.println("您還未進(jìn)行賬戶登錄");
  }
 }
 /**
  * 取款操作
  */
 public void withdraw(){
  Scanner input=new Scanner(System.in);
  System.out.println("請(qǐng)輸入你要取出的金額為:");
  int money=input.nextInt();
  if(loginuser!=null){
   if(money>0&&money<=loginuser.getBlance()){
    loginuser.setBlance(loginuser.getBlance()-money);
    System.out.println("取款成功");
    System.out.println("您的當(dāng)前余額為:"+loginuser.getBlance());
   }else{
    System.out.println("輸入錯(cuò)誤");
   }
  }else{
   System.out.println("您還未進(jìn)行賬戶登錄");
  }
 }
 /**
  * 轉(zhuǎn)賬操作
  */
 public void trans(){
  Scanner input=new Scanner(System.in);
  System.out.println("請(qǐng)輸入要轉(zhuǎn)入賬戶的卡號(hào):");
  String cardNo=input.next();
  User nuser=null;//對(duì)方賬戶
  boolean IsExit=false;//判斷對(duì)方賬戶是否存在
  for (int i = 0; i <size; i++) {
   if(users[i].getCardNo().equals(cardNo)){
    IsExit=true;//檢索到對(duì)方賬戶
    nuser=users[i];
   }
  }
  if(loginuser==nuser){
   System.out.println("不可以自己給自己賬戶進(jìn)行轉(zhuǎn)賬");
   return;
  }
  if(loginuser!=null){
   System.out.println("請(qǐng)輸入要轉(zhuǎn)賬的金額:");
   int money=input.nextInt();
   if(money>0&&money<=loginuser.getBlance()){
    loginuser.setBlance(loginuser.getBlance()-money);
    nuser.setBlance(nuser.getBlance()+money);
    System.out.println("轉(zhuǎn)賬成功");
    System.out.println("您當(dāng)前余額為"+loginuser.getBlance());
    System.out.println(nuser.getBlance());
   }else{
    System.out.println("輸入錯(cuò)誤");
   }
  }else{
   System.out.println("請(qǐng)登錄賬戶");
  }
 }
 /**
  * 查詢余額
  */
 public void query(){

  System.out.println("您的余額為:"+loginuser.getBlance());
 }
 /**
  * 修改密碼
  */
 public void revise(){
  Scanner input=new Scanner(System.in);
  System.out.println("請(qǐng)輸入您的新密碼");
  int newpassword=input.nextInt();
  for (int i = 0; i < size; i++) {
   if(users[i]==loginuser){
    users[i].setPassword(newpassword); //進(jìn)行修改
   }
  }
  System.out.println("密碼修改成功");
 }
}

BankSystem.java

public class BankSystem {
 public static void main(String[] args) {
  Scanner input=new Scanner(System.in);
  Bank bank=new Bank();
   System.out.println("請(qǐng)輸入您的卡號(hào):");
   String cardNo=input.next();
   System.out.println("請(qǐng)輸入您的密碼:");
   int password=input.nextInt();
   User user = bank.login(cardNo, password);//用戶登錄
   if(user!=null){
    System.out.println(user.getUsername()+"登陸成功");
    bank.showMenus();
   }else{
    System.out.println("登陸失敗");
   }
 }
}

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

相關(guān)文章

  • 詳解如何為SpringBoot Web應(yīng)用的日志方便追蹤

    詳解如何為SpringBoot Web應(yīng)用的日志方便追蹤

    在Web應(yīng)用程序領(lǐng)域,有效的請(qǐng)求監(jiān)控和可追溯性對(duì)于維護(hù)系統(tǒng)完整性和診斷問(wèn)題至關(guān)重要,SpringBoot是一種用于構(gòu)建Java應(yīng)用程序的流行框架,在本文中,我們探討了在SpringBoot中向日志添加唯一ID的重要性,需要的朋友可以參考下
    2023-11-11
  • 解析Java中所有錯(cuò)誤和異常的父類java.lang.Throwable

    解析Java中所有錯(cuò)誤和異常的父類java.lang.Throwable

    這篇文章主要介紹了Java中所有錯(cuò)誤和異常的父類java.lang.Throwable,文章中簡(jiǎn)單地分析了其源碼,說(shuō)明在代碼注釋中,需要的朋友可以參考下
    2016-03-03
  • Java中類的初始化和實(shí)例化區(qū)別詳解

    Java中類的初始化和實(shí)例化區(qū)別詳解

    這篇文章主要介紹了Java中類的初始化和實(shí)例化區(qū)別詳解,類的初始化<BR>是完成程序執(zhí)行前的準(zhǔn)備工作,類的實(shí)例化(實(shí)例化對(duì)象)是指創(chuàng)建一個(gè)對(duì)象的過(guò)程,需要的朋友可以參考下
    2023-08-08
  • SpringBoot部署在Weblogic的操作步驟

    SpringBoot部署在Weblogic的操作步驟

    這篇文章主要介紹了SpringBoot部署在Weblogic的操作步驟,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Java數(shù)據(jù)結(jié)構(gòu)之循環(huán)隊(duì)列簡(jiǎn)單定義與用法示例

    Java數(shù)據(jù)結(jié)構(gòu)之循環(huán)隊(duì)列簡(jiǎn)單定義與用法示例

    這篇文章主要介紹了Java數(shù)據(jù)結(jié)構(gòu)之循環(huán)隊(duì)列簡(jiǎn)單定義與用法,簡(jiǎn)要描述了循環(huán)隊(duì)列的概念、原理,并結(jié)合實(shí)例形式分析了java循環(huán)隊(duì)列的定義與使用方法,需要的朋友可以參考下
    2017-10-10
  • Java面向?qū)ο蠡A(chǔ)知識(shí)之抽象類和接口

    Java面向?qū)ο蠡A(chǔ)知識(shí)之抽象類和接口

    這篇文章主要介紹了Java面向?qū)ο蟮某橄箢惡徒涌?文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)java基礎(chǔ)的小伙伴們有很好的幫助,需要的朋友可以參考下
    2021-11-11
  • Intellij IDEA中一次性折疊所有Java代碼的快捷鍵設(shè)置

    Intellij IDEA中一次性折疊所有Java代碼的快捷鍵設(shè)置

    這篇文章主要介紹了Intellij IDEA中一次性折疊所有Java代碼的快捷鍵設(shè)置,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Java你告訴我 fail-fast 是什么鬼

    Java你告訴我 fail-fast 是什么鬼

    這篇文章主要介紹了Java你告訴我 fail-fast 是什么鬼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • BeanUtils.copyProperties在拷貝屬性時(shí)忽略空值的操作

    BeanUtils.copyProperties在拷貝屬性時(shí)忽略空值的操作

    這篇文章主要介紹了BeanUtils.copyProperties在拷貝屬性時(shí)忽略空值的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • java使用socket實(shí)現(xiàn)一個(gè)多線程web服務(wù)器的方法

    java使用socket實(shí)現(xiàn)一個(gè)多線程web服務(wù)器的方法

    今天小編就為大家分享一篇java使用socket實(shí)現(xiàn)一個(gè)多線程web服務(wù)器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10

最新評(píng)論