zoukankan      html  css  js  c++  java
  • Bank1

    Bank1:

    package banking1;
    
    //账户
    public class Account {
        private double balance;// 账户余额
    
        public Account(double init_balance) {
            balance = init_balance;
        }
    
        public double getBlance() {
            return balance;
        }
    
        // 存钱
        public void deposit(double amt) {// amt 要存的额度
            balance += amt;
        }
    
        // 取钱
        public void withdraw(double amt) {// amt:要取得额度
            if (balance >= amt) {
                balance -= amt;
            } else {
                System.out.println("余额不足");
            }
        }
    }

    TestBanking1:

    /*
     * This class creates the program to test the banking classes.
     * It creates a new Bank, sets the Customer (with an initial balance),
     * and performs a series of transactions with the Account object.
     */
    package TestBanking;
    
    import banking1.Account;
    
    public class TestBanking1 {
        public static void main(String[] args) {
            Account account;
    
            // Create an account that can has a 500.00 balance.
            account = new Account(500.00);
            System.out.println("Creating an account with a 500.00 balance.");
    
            // code
            account.withdraw(150);
            System.out.println("Withdraw 150.00");
            // code
            account.deposit(22.50);
            System.out.println("Deposit 22.50");
    
            // code
            account.withdraw(47.62);
            System.out.println("Withdraw 47.62");
            // code
            // Print out the final account balance
            System.out.println("The account has a balance of " + account.getBlance());
        }
    }


    输出结果:

    Creating an account with a 500.00 balance.
    Withdraw 150.00
    Deposit 22.50
    Withdraw 47.62
    The account has a balance of 324.88

     
    All that work will definitely pay off
  • 相关阅读:
    JAVA_Collection容器
    ArrayList实现分组功能
    scrapy 安装出错 [err2] no such file or directory: 'README.rst'【已解决】
    python spyder 今天突然打不开了【已解决】
    SVN使用教程总结
    MVC框架浅析(基于PHP)
    Web性能优化方案
    野生程序员的故事
    js控制页面跳转,清缓存,强制刷新页面
    js中json处理总结之JSON.parse
  • 原文地址:https://www.cnblogs.com/afangfang/p/12485757.html
Copyright © 2011-2022 走看看