package com.atguigu.exercise2;
public class CustomerTest {
public static void main(String[] args) {
Customer cust = new Customer("Jane","Smith");
Account acct = new Account(1000,2000,0.0123);
cust.setAccount(acct);
//存取操作
//cust.getAccount();
acct.deposit(100);//存钱
acct.withdraw(960);//取钱
acct.withdraw(2000);//取钱
}
}
package com.atguigu.exercise2;
public class Account {
//属性
private int id;//账号
private double balance;//余额
private double annuallnterestRate;//年利率
//构造器
public Account(int id, double balance, double annuallnterestRate){
this.id = id;
this.balance = balance;
this.annuallnterestRate = annuallnterestRate;
}
//方法
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnuallnterestRate() {
return annuallnterestRate;
}
public void setId(int id) {
this.id = id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnuallnterestRate(double annuallnterestRate) {
this.annuallnterestRate = annuallnterestRate;
}
public void withdraw(double amount){ //取钱
if(balance < amount){
System.out.println("余额不足,取款失败!");
return;
}
balance -= amount;
System.out.println("成功取出:"+amount);
}
public void deposit(double amount){ //存钱
if(amount > 0){
balance += amount;
System.out.println("成功存入:" + amount);
}else{
System.out.println("存款失败!");
}
}
}
package com.atguigu.exercise2;
public class Customer {
//属性
private String firstName;
private String lastName;
private Account account;
//构造器
public Customer(String f, String l){
this.firstName = f;
this.lastName = l;
}
//方法
public String getfirstName(){
return firstName;
}
public String getlastName(){
return lastName;
}
public Account getAccount(){
return account;
}
public void setAccount(Account account){
}
}