【Homework】银行存取款业务
生活随笔
收集整理的這篇文章主要介紹了
【Homework】银行存取款业务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
要求:
(1)創建類CheckingAccount對每次存款取款收取1元手續費。
(2)每個月都有利息,且每個月都有三次免手續費存取款。
/*** @className: Homework08* @description:* @date: 2021/12/24 21:09**/ public class Homework08 {public static void main(String[] args) {SavingsAccount savingsAccount = new SavingsAccount(1000);savingsAccount.deposit(100);savingsAccount.withdraw(100);savingsAccount.withdraw(100);System.out.println(savingsAccount.getBalance());savingsAccount.deposit(100);System.out.println(savingsAccount.getBalance());} } /*** @className: CheckingAccount* @description:* @date: 2021/12/24 20:45**/ public class CheckingAccount extends BankAccount{private double fee = 1;public CheckingAccount(double initialBalance) {super(initialBalance);}//收取手續費的存款過程@Overridepublic void deposit(double amount) {super.deposit(amount - 1);}//收取手續費的取款過程@Overridepublic void withdraw(double amount) {super.withdraw(amount + 1);}public double getFee() {return fee;}public void setFee(double fee) {this.fee = fee;} } /*** @className: SavingsAccount* @description:* @date: 2021/12/24 20:57**/ public class SavingsAccount extends BankAccount{private int count = 3;//次數private double rate = 0.01;//利率public SavingsAccount(double initialBalance) {super(initialBalance);}public void earnMonthlyInterest() {//月初重置免手續費次數,結算利息count = 3;super.deposit(getBalance() * rate);}@Overridepublic void deposit(double amount) {//每月有三次免手續費存款或者取款if(count > 0){super.deposit(amount);}else {super.deposit(amount - 1);}count--;}@Overridepublic void withdraw(double amount) {//每月有三次免手續費存款或者取款if(count > 0) {super.withdraw(amount);} else {super.withdraw(amount + 1);}count--;}public int getCount() {return count;}public void setCount(int count) {this.count = count;}public double getRate() {return rate;}public void setRate(double rate) {this.rate = rate;} } 超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的【Homework】银行存取款业务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【修饰符】四种访问修饰符和各自的权限
- 下一篇: 【Homework】说出 == 和 eq