public class Bank{
private CheckingAccount accountOne;
private CheckingAccount accountTwo;
public Bank(){
accountOne = new CheckingAccount("Zeus", 100, "1");
accountTwo = new CheckingAccount("Hades", 200, "2");
}
public static void main(String[] args){
Bank bankOfGods = new Bank();
bankOfGods.accountOne.setBalance(5000);
System.out.println(bankOfGods.accountOne.getBalance());
}
}
//other file with private classes
public class CheckingAccount{
private String name;
private int balance;
private String id;
public CheckingAccount(String inputName, int inputBalance, String inputId){
name = inputName;
balance = inputBalance;
id = inputId;
}
//Write new methods here:
public int getBalance() {
return balance;
}
public void setBalance(int newBalance) {
balance = newBalance;
}
}
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