zoukankan      html  css  js  c++  java
  • 银行管理

    public class Bank {
    String account ;
    int account_num;
    public Bank(String account,int account_num){
    this.account=account;
    this.account_num=account_num;
    }
    //存钱
    public String addNum(int num){
    account_num= account_num+num;
    return "存钱成功";
    }
    //取钱
    public String getNum(int num){
    String result;
    if(account_num>num){
    account_num =account_num-num;
    result="取钱成功";
    }else{
    result="账户余额不足,还剩"+account_num;
    }
    return result;
    }
    //显示余额
    public String displayNum(){
    return "账户余额:"+account_num;
    }
    //显示账号
    public String displayAccount(){
    return "账户:"+account;
    }
    public static void main(String[] args){
    Bank lucy = new Bank("lucy",100);
    Bank jack = new Bank("jack",50);
    //显示他们各自的余额
    System.out.println("===显示他们各自的余额===");
    System.out.println("lucy:"+lucy.displayNum());
    System.out.println("jack:"+jack.displayNum());
    //存钱取钱
    System.out.println("===存钱取钱===");
    System.out.println("lucy取50:"+lucy.getNum(50));
    System.out.println("jack存200:"+jack.addNum(200));
    //显示账户 显示余额
    System.out.println("===账户余额===");
    System.out.println(lucy.displayAccount()+""+lucy.displayNum());
    System.out.println(jack.displayAccount()+""+jack.displayNum());
    }
    }

     ===显示他们各自的余额===
    lucy:账户余额:100
    jack:账户余额:50
    ===存钱取钱===
    lucy取50:取钱成功
    jack存200:存钱成功
    ===账户余额===
    账户:lucy账户余额:50
    账户:jack账户余额:250
  • 相关阅读:
    常用C# 6.0 常用 新特性
    VS 编译总是出现错误: "LC.EXE 已退出,代码为1"
    C# XML封装
    VS 2015秘钥
    写入Txt文本信息
    C# 7.0 新特性
    Winform 弹框增加确定按钮并点击确定后进行下一步操作
    VS 代码过长自动换行
    C# 6.0 新特性
    string::npos 是什么 c++ /STL
  • 原文地址:https://www.cnblogs.com/kongdexiu-13/p/8977349.html
Copyright © 2011-2022 走看看