首页 > 代码库 > this 学习笔记 2
this 学习笔记 2
package ctgu.java; public class Account { private int id ; private double balance; private double annualTnterestRate; public Account(int id, double balance, double annualTnterestRate) { super(); this.id = id; this.balance = balance; this.annualTnterestRate = annualTnterestRate; } 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 getAnnualTnterestRate() { return annualTnterestRate; } public void setAnnualTnterestRate(double annualTnterestRate) { this.annualTnterestRate = annualTnterestRate; } 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); } }
package ctgu.java; public class Customer { private String firstName; public Account getAccount() { return account; } public void setAccount(Account account) { this.account = account; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } private String lastName; private Account account; public Customer(String f, String l) { this.firstName = f; this.lastName = l; } }
package ctgu.java; public class TestCustomer { public static void main(String[] args) { Customer cust = new Customer("Jane","Smith"); cust.setAccount(new Account(1000, 2000, 0.0123)); Account account = cust.getAccount(); account.deposit(100); account.withdraw(960); account.withdraw(2000); System.out.println("Customer ["+ cust.getLastName() + "," +cust.getFirstName()+"] has a account:id is" + account.getId()+ ", annualTnterestRate is" + account.getAnnualTnterestRate()*100 + "%,balance is"+ account.getBalance()); } }
this 学习笔记 2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。