标签:private package balance public double
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()); } }
标签:private package balance public double
原文地址:http://9815936.blog.51cto.com/9805936/1605338