Other Private Methods
Wed Nov 09 2022 05:00:07 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
public class Bank{
private CheckingAccount accountOne;
private CheckingAccount accountTwo;
public Bank(){
this.accountOne = new CheckingAccount("Zeus", 100, "1");
this.accountTwo = new CheckingAccount("Hades", 200, "2");
}
public static void main(String[] args){
Bank bankOfGods = new Bank();
bankOfGods.accountOne.getAccountInformation();
bankOfGods.accountOne.calculateNextMonthInterest();
}
}
//next page
public class CheckingAccount{
private String name;
private int balance;
private String id;
private double interestRate;
public CheckingAccount(String inputName, int inputBalance, String inputId){
this.name = inputName;
this.balance = inputBalance;
this.id = inputId;
this.interestRate = 0.02;
}
public void getAccountInformation(){
System.out.println("Money in account: " + this.getBalance());
System.out.println("Next Month's Interest: " + this.calculateNextMonthInterest());
}
private int getBalance(){
return this.balance;
}
// Write the calculateNextMonthInterest() here
private double calculateNextMonthInterest(){
return this.interestRate * this.balance;
}
}
content_copyCOPY
Comments