1. 程式人生 > >簡單的,到處是bug的,菜鳥自學初學寫的,Java的銀行存取款程式碼

簡單的,到處是bug的,菜鳥自學初學寫的,Java的銀行存取款程式碼

   }
/*註冊*/    void register(){
        p("請輸入賬號");
        String newName = getString();
        p("請輸入註冊密碼");
        String newPsw = getString();
     for (int i=0;i<uresALL.size();i++) {
      if (newName.equals(uresALL.get(i).name)){
        p("賬號已存在");
        return;
       }
      }  int money = 0;
        URES ures = new URES(newName,newPsw,money);
        uresALL.add(ures);
        p("註冊成功");
        isRegister = true;
     }
/*判斷賬號密碼*/  void login(){
     p("輸入賬號");
     String n = getString();
     p("輸入密碼");
     String p = getString();
     int j = 4;
    for (int i=0;i<uresALL.size();i++){
     if (n.equals(uresALL.get(i).name) && p.equals(uresALL.get(i).psw)) {
       this.i = i;
       p("登入成功");
       isLogin = true;
       j = 1;
       return;
      }   
      } 
     if (j==4) {
      p("登入失敗");
     }
     
      }
/*第二個介面*/   void menu(){
     p("選單 1.餘額  2.存款  3.取款  4.登出");
     switch (getInt()) {
      case 1:
       p("你的餘額為"+uresALL.get(i).money);
       break;
      case 2:
       moneycun();
       break;
      case 3:
       moneyqu();
       break;
      case 4:
       isLogin = false;
       break;
      default :
       p("選擇錯誤請重新選擇");
     }
    }
/*存款處理方式*/  void moneycun(){
       
       p("輸入存款金額");
       int money = getInt();
       if (money<1) {
        p("金額方式不對");
       }else{
        uresALL.get(i).money = uresALL.get(i).money + money;
        p("你的餘額為:"+uresALL.get(i).money);
       }
      }
/*取款處理方式*/  void moneyqu(){
       p("輸入取款金額");
       int moneyqu = getInt();
        if (moneyqu<1) {
         p("金額方式不對");
        }else if(uresALL.get(i).money<moneyqu){
         p("餘額不足");
        }else{
         uresALL.get(i).money = uresALL.get(i).money-moneyqu;
         p("你的餘額為:"+uresALL.get(i).money); 
        }
       }   
/*輸出啥*/    void p(String a){
    System.out.println(a);
    }
/*獲得整數型別*/  int getInt(){
    Scanner sc = new Scanner(System.in);
    return sc.nextInt();
    }
/*獲得字串型別*/  String getString(){
    Scanner sc = new Scanner(System.in);
    return sc.nextLine();
    }
}