package com.jerry.experiment1;
/**
* @author jerry_jy
* @create 2022-09-29 10:44
*/
public class Account {
private int id;
private double balance;
private double annualInterestRate;
public Account() {
}
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 (this.getBalance() < amount) {
System.out.println("余额不足!您的账户余额为:" + this.getBalance());
} else {
System.out.println("取款成功!本次取款金额为:" + amount);
System.out.println("账户余额为:" + (this.getBalance() - amount));
System.out.println("月利率为:" + this.getAnnualInterestRate());
}
}
public void deposit(double amount) {//存钱
System.out.println("存款成功!本次存款金额为:" + amount);
System.out.println("账户余额为:" + (this.getBalance() + amount));
System.out.println("月利率为:" + this.getAnnualInterestRate());
}
}
class CheckAccount extends Account {
double overdraft;
public double getOverdraft() {
return overdraft;
}
public void setOverdraft(double overdraft) {
this.overdraft = overdraft;
}
public CheckAccount() {
}
public CheckAccount(int id, double balance, double annualInterestRate, double overdraft) {
super(id, balance, annualInterestRate);
this.overdraft = overdraft;
}
public void withdraw(double amount) {//取钱
if (amount < this.getBalance()) {
System.out.println("取款成功!本次取款金额为:" + amount);
System.out.println("您的账户余额为:" + (this.getBalance() - amount));
double temp = this.getBalance() - amount;
this.setBalance(temp);
System.out.println("您的可透支额度:" + this.getOverdraft());
} else if (amount < (this.getBalance() + this.getOverdraft())) {
double temp = this.getBalance() + this.overdraft - amount;
this.setOverdraft(temp);
this.setBalance(0);
System.out.println("取款成功!本次取款金额为:" + amount);
System.out.println("您的账户余额为:" + this.getBalance());
System.out.println("您的可透支额度:" + this.getOverdraft());
} else {
System.out.println("超过可透支额度!您的可透支额度:" + overdraft);
}
}
}