面向对象综合练习1

 

package com.g.x.fengzhuang;

public class CustomTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Customer cust = new Customer("hh", "lll");
    
        Account acc = new Account(1001, 2000, 0.0136);
        cust.setAccount(acc);
        cust.getAccount().deposit(33);
        cust.getAccount().getId();
        System.out.println(cust.getAccount().getId());
    }
    
}

****************************************************

package com.g.x.fengzhuang;

public class Account {
    private int id;//账号
    private double balance;//余额
    private double annualInterestRate;//年利率
    
    public Account() {
        super();
    }
    
    public Account(int id, double balance, double annualInterestRate) {
        super();
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }
    
    public void withdraw(double amount) {  //取钱
        if (amount > balance) {
            System.out.println("no money");
        }
        balance -= amount;
        System.out.println("out success:"+amount);
        
    }
    
    public void deposit(double amount) {  //存钱
        if (amount > 0) {
            balance += amount;
            System.out.println("input success :"+amount);
        }
    }
    
    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;
    } 

}

***********************************************************

package com.g.x.fengzhuang;

public class Customer {
    private String firstname;
    private String lasename;
    private Account account;
    
    public Customer() {
        super();
    }
    public Customer(String firstname, String lasename, Account account) {
        super();
        this.firstname = firstname;
        this.lasename = lasename;
        this.account = account;
    }
    
    public Customer(String f,String l) {
        this.firstname = f;
        this.lasename = l;
    }
    
    public String getFirstname() {
        return firstname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public String getLasename() {
        return lasename;
    }
    public void setLasename(String lasename) {
        this.lasename = lasename;
    }
    public Account getAccount() {
        return account;
    }
    public void setAccount(Account account) {
        this.account = account;
    }
    
    

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值