zoukankan      html  css  js  c++  java
  • This关键字练习

    Account:

    package com.aff.ex;
    
    public class Account {
        private int id;// 账号
        private double balance;// 余额
        private double annualInterestRate;// 年利率
    
        public Account(int id, double balance, double annualInterestRate) {
            this.id = id;
            this.balance = balance;
            this.annualInterestRate = annualInterestRate;
        }
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public double getBalance() {
            return balance;
        }
    
        public void setBalance(double balance) {
            this.balance = balance;
        }
    
        public double getAnnualInterestRate() {
            return annualInterestRate;
        }
    
        public void setAnnualInterestRate(double annualInterestRate) {
            this.annualInterestRate = annualInterestRate;
        }
    
        // 取钱
        public void withdraw(double amount) {
            if (balance >= amount) {
                balance -= amount;
                System.out.println("成功取出" + amount);
            } else {
                System.out.println("余额不足");
            }
        }
    
        // 存钱
        public void deposit(double amount) {
            balance += amount;
            System.out.println("成功存入" + amount);
        }
    
    }

    Customer:

    package com.aff.ex;
    
    public class Customer {
        private String fristName;
        private String lastName;
        private Account account;
    
        public Customer(String f, String l) {
            this.fristName = f;
            this.lastName = l;
        }
    
        public Account getAccount() {
            return account;
        }
    
        public void setAccount(Account account) {
            this.account = account;
        }
    
        public String getFristName() {
            return fristName;
        }
    
        public String getLastName() {
            return lastName;
        }
    
    }

    TestCustomer:

    package com.aff.ex;
    
    //创建一个Customer,起名叫Jane Smith,
    //他账号为1000 ,余额2000,年利率1.23%
    //操作:  存入100,再取出950,再取出2000,打印Jane Smith的基本信息
    public class TestCustomer {
        public static void main(String[] args) {
            Customer cus = new Customer("Jane", "Smith");
            cus.setAccount(new Account(1000, 2000, 0.0123));// 使用匿名的方式创建
            Account acc = cus.getAccount();
            acc.deposit(100);
            acc.withdraw(960);
            acc.withdraw(2000);
            System.out.println("Customer[" + cus.getLastName() + "," + cus.getFristName() 
    + "] has a account: id is" + acc.getId() + "annualInterestRate" + acc.getAnnualInterestRate() * 100 + "%" + "balance is" + acc.getBalance()); } }

    输出结果:

    成功存入100.0
    成功取出960.0
    余额不足
    Customer[Smith,Jane] has a account: id is1000annualInterestRate1.23%balance is1140.0

     
    All that work will definitely pay off
  • 相关阅读:
    关于python urlopen 一个类似radio流的timeout方法
    Python nltk English Detection
    Python依赖打包发布详细
    python 怎么和命令行交互
    Python中多维数组flatten的技巧
    Python中的url编码问题
    python数据持久存储:pickle模块的基本使用
    Python控制台输出不换行(进度条等)
    UnicodeEncodeError: 'ascii' codec can't encode character u'xe9' in position 7: ordinal not in range(128) [duplicate]
    json.loads(s) returns error message like this: ValueError: Invalid control character at: line 1 column 33 (char 33)
  • 原文地址:https://www.cnblogs.com/afangfang/p/12515121.html
Copyright © 2011-2022 走看看