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; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter