Account II
URL: https://www.onlinegdb.com/classroom/Fd0aduv55
Requirements
Instance variables:
double interestRate
: a double variable indicating the monthly interest rates. For example, if theinterstRate
is 2, it means monthly interest rate is 2%.double fee
: a double variable indicating a monthly fee charged to the account, if the balance is below a threshold.double threshold
: a double variable indicating the minimum balance required to avoid the monthly fee.
2.Static Variable:
accountCount
: an integer static variable to keep track of the number of Account instances created.
3.Constructors:
Since you add three instance variables, so you should modify your constructors like this:public Account(String accountHolder, String accountNumber,double balance, double interestRate, double fee, double threshold) {...}Each time an new account is created, accountAcount
should increase by 1.
4.New Methods:
public static int getAccountCount()
: returns the current value ofaccountCount.
private void applyInterest()
: applies a monthly interest rate to the balance.private void chargeFee()
: charges a fee if the balance is below a specified threshold.public void passMonth()
: simulates the passage of a month. It will first apply interest to the balance of the account. If the new balance is below threshold, it will be charge a fee.For example, is the current balance is 100, monthly interest rate is 10%, threshold is 200, and the fee is 5.
When a month passed, the balance will get interests, become 100 + 100*10%=110.0. Since it is below threshold(200), the account will be charged a ¥5 fee.
So the account should have ¥105.0 after the month passed.
applyInterest
and chargeFee
should be private, meaning they can only be called within the Account class.Hint: applyInterest() and chargeFee() is triggered monthly, so they should be only called by passMonth().
4.The following table contains a code execution sequence and the corresponding results:
Statement of Expression
Return Value
Explanation
Account a1 = new Account("John Doe", "12345678", 100, 10, 20, 200);
N/A
Create account a1 with initial balance of ¥100, 10% monthly interest, ¥20 fee, ¥200 threshold.
Account.getAccountCount();
1
Returns the total number of accounts created after a1's creation.
a1.deposit(150);
true
Deposit of ¥150 to a1.
a1.getBalance();
250.0
Balance in a1 after deposit.
a1.passMonth();
N/A
Simulate a month passing for a1.
a1.getBalance();
275.0
Balance in a1 after a month, with interest. There is no fee charged, since 275.0 is larger than 200.
a1.withdraw(130);
true
Withdraw ¥130 from a1.
a1.getBalance();
145.0
Balance in a1 after withdrawal.
a1.passMonth();
N/A
Simulate another month passing for a1.
a1.getBalance();
139.5
Balance in a1 after second month, with interest applied. There is a ¥10 fee charged, so the balance is 145*1.1-20 = 139.5。
Account a2 = new Account("Jane Smith", "87654321", 50, 20, 10, 200);
N/A
Create account a2 with initial balance of ¥50, 20% monthly interest, ¥10 fee, ¥200 threshold.
Account.getAccountCount();
2
Returns the total number of accounts created after a2's creation.
a2.deposit(50);
true
Deposit of ¥50 to a2.
a2.getBalance();
100.0
Balance in a2 after deposit.
a2.passMonth();
N/A
Simulate a month passing for a2.
a2.getBalance();
110.0
Balance in a2 after a month, with interest and fee charged. The balance is 100*1.2-10 = 110.0.
a2.withdraw(20);
true
Withdraw ¥20 from a2.
a2.getBalance();
90.0
Balance in a2 after withdrawal.
a2.passMonth();
N/A
Simulate another month passing for a2.
a2.getBalance();
98.0
Balance in a2 after second month, with interest and fee charged. The balance is 90*1.2-10 = 98.0.
FULL SCORE
Zhu Qixin
Dong Ruoxuan
He Yuhan
Jin Xuanyu
Lin Jiaxin
Luo Rui
Wang Jiaxi
Zhang Wenyuan
Zheng Hao
Zhu Yi
Liu Xintong
Zhang Tianyu
Ding Chengtian
Ni Jiachen
Zhang Xiaowen
ALMOST THERE
Wang Yueqi
Hu Yuqin
Lyu Jiajia
Chen Sihan
Li Jiakang
Last updated