zoukankan      html  css  js  c++  java
  • ATM

    ATM 问题或找对象
    名词: 账号、 密码、 用户、 ATM机、 余额、 现金

    类:ATM、 用户:(信息)

    属性:现金、 余额、 账号、 密码
    用户信息

    行为:登陆、查、改、取、存、退出、选择菜单、欢迎界面。

    package com.love.bean;

    import java.util.Scanner;

    public class ATMMachine{

       private UserBean[] theUser;//用户信息数组

       private UserBean myUser;//当前用户

       private int cash = 200000;//现金

       public final int MAX_CASH = 1000000;//最大现金额度

       public ATMMachine(){
          // TODO Auto-generated constructor stub

          //用户信息初始化---现在暂时是假数据“账号:123+i”、“密码:123+i”,初始现金金额:随机
          this.theUser = new UserBean[5];
          foe(int i=0; i<theUser.length; i++){
          theUser[i] = new User("123" + i,"123" + i,(int)(Math.radom()*100+1));
           }
        }

      //运行

      public void rum(){

        this.welcome(){//进入欢迎界面

        boolean flag = this. longin();//进入登陆界面

        if(flag){

          while(true){

            int choice = this. chooseMenu();//进入选择菜单

            switch(choice){

            case 1 :

              this.query();//查询

              break;       

            case 2 :

              this.storeMoney();//存款

              break;

            case 3 :

              this.getMoney();//取款

              break;

            case 4 :

              this.changePwd();/修改密码

              break;

            case 5 :

              this.exit();//退出

              break;

            default: :

              System.out.println("无此选项!");

              break;

            }

          }

        }else{

          System.out.println("你的卡被没收,请带上有效证件到前台处理!");

        }

       }

      //欢迎界面

      private void welcome(){

        System.out.println("***************************");

        System.out.println("***********欢      迎**********");
        System.out.println("***********使      用**********");
        System.out.println("**********爱存不存银行********");
        System.out.println("***************************");
      }

      //登陆

      private boolean login(){

        Scanner scan = new Scanner(System.in);

        for(int i=0; i<3; i++){  //设置3次登陆机会

          System.out.println("请输入用户名:");

          String inputCardNum = scan.next();

          System.out.println("请输入用户密码:");

          String inputPwt = scan.next();

          for(int j=0; j<theUser; j++){

            if(theUser[j].getCarfNum().equals(inputCardNum) && theUser[j].getPassworf().equals(inputPwd)){  //调用get方法查看输入账号与输入密码是否相同 (&&判断两边必须都为真,一边为假则都为假)

            System.out.println("登陆成功!);

            myUser = theUser[i]; // 赋值用户信息给当前用户

            System.out.println(myUser.getCardNum() + "," + myUser.gerPassword()); //  打印当前用户 账号、密码

            returm trus;

            }

            System.out.println("用户名或密码错误,还有“ + (2-i) + "次机会。");//   _反馈还剩登陆次数 

          }

        }

        return false;

      }

      //选择菜单

      private int chooseMenu(){

        Scanner sc = new Scanner(Syatem.in);

        int ny = 0;

        while ( true){

          System.out.println("输入所选泽菜单:");

          System.out.println("1:查询余额:");

          System.out.println("2:存款:");

          System.out.println("3:取款:");

          System.out.println("4:修改密码:");

          System.out.println("3:退出:");

          ny = sc.nextInt();

          return ny;

        }  

      }

      //查询余额

      private void query(){

        System.out.println("当前余额:" + myUser.getAccount());  _ 表示当前用户信息中现金余额;

      }

      //存款

      private void storeMoney(){

        Scanner cunqian = new Scanner(System.in);

        int fangqian = 0;  

        System.out.println("提示:存入金额必须为100元,或100元的倍数!");

        System.out.println("请输入金额:");

        fangqian = cunqian.nextInt();

        while(fangqian <=0 || fangqian %100 !=0 || (fangqian + cash) >MAX_CASH){

          if(fangqian <= 0){

            System.out.println("存入金额应大于0!");

          }else if(fangqian %100 !=0){

            System.out.println("存入金额应为100元,或100元倍数");

          }else {

            System.out.println(存入金额与ATM机放置金额超出ATM机存放最大金额);

          }

          System.out.println("请重新输入存入金额:");

          fangqian = cunqian.nextInt();

        }

        this.cash += fangqian;  // 用户现金加上存入金额;

        myUser.setAccount(fangqian + myUser.getAccount()); //使用set方法修改账户余额;

        System.out.println("存款成功!");

      }

      //取款

      private void getMoney(){

        Scanner quMoney = new Scanner(System.in);

        int quqian = 0;

        System.out.println("输入取款金额:");

        quqian = quMoney.nextInt();

        while(quqian <= 0 || quqian%100 !=0 || quqian> cash || quqian>myUser.getAccount()){

          if(quqian = 0){

            System.out.println("取款金额应大于0!");

          }else if(quqian %100 !=0){

            System.out.println("取款金额应为100元,或100元的倍数!");

          }else if(quqian > myUser.getAccount()){

            System.out.println("取款金额大于账户余额!");

          }  

        System.out.println("请重新输入取款金额:");

        quqian = quMoney.nextInt();

        }

        this.cash -= quqian; // 用户现金减去取款金额;

        myUser.setAccount(myUser.gatAccount() -quqian);//用set方法修改用户余额

      }

      //改密码

      private void changePwd(){

        Scanner mi = new Scanner(System.in); 

        int cishu = 3;

        System.out.println("请输入当前用户密码:");

        String mima = mi.next();

        while(!myUser.getPassword().equals(mima)){

          cishu--;

          if(cishu = 0){

            System.out.println("3次密码输入错误,返回选择菜单!");

            retur;

          }

          System.out.println("密码错误!");

          System.out.println("你还有" + cishu + "机会!");

          mima = mi.next();

        }

        System.out.println("请输入当前用户新密码:");

        mima = mi.next();

        myUser.setpassword(mima);

        System.out.println("密码修改成功!");

      }

      //退出

      private void exit(){

        System.out.println("退出!);

        System.out.println("请取出银行卡!");

        System.exit(0);

      }

    }

    // 设置用户信息

    //  用户信息调用(使用get/set 方法)

    //  用户信息---标准Java类;

    public class UserBean{

      private String cardNum;//卡号

      private String password;//密码

      private double account;//账户余额

      public UserBean(){

      }

      

      public UserBean(String cardNum, String password, double account) {
        this.cardNum = cardNum;
        this.password = password;
        this.account = account;
      }

      public String getCardNum() {
        return cardNum;
      }

      public void setCardNum(String cardNum) {
        this.cardNum = cardNum;
      }

      public String getPassword() {
        return password;
      }

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

      public double getAccount() {
        return account;
      }

      public void setAccount(double account) {
        this.account = account;
      }

    }

    //设置mian运行

    public class TestMain{

      public static void mian(String[] args){

        ATMMachine atm = new ATMMachine();

        atm.run();

      }

    }

  • 相关阅读:
    SpringMVC统一异常处理
    How to convert BigDecimal to Double in spring-data-mongodb framework
    DHCP动态主机配置协议
    你所听到的技术原理、技术本质到底是什么?
    前端技术及开发模式的演进,带你了解前端技术的前世今生
    金三银四,如何征服面试官,拿到Offer
    何谓多租户模式 ?
    骄傲的技术人,技术是你的全部吗?
    自我剖析,坚持有多难?
    从官方文档去学习之FreeMarker
  • 原文地址:https://www.cnblogs.com/scxu28/p/6129273.html
Copyright © 2011-2022 走看看