I have a couple questions:
1) I do not understand the part on how to populate the Arraylist. I do understand that we can't create instances of Money but what are we adding to this lis?
2) what is happening here?
"Person paul = new Person("Paul");
for (Money money : paul.getAllMoney()) "
Thanks for educating me in advance!
package com.codegym.task.task14.task1417;
import java.util.ArrayList;
import java.util.List;
/*
Currencies
*/
public class Solution {
public static void main(String[] args) {
Person paul = new Person("Paul");
for (Money money : paul.getAllMoney()) {
System.out.println(paul.name + " has a stash of " + money.getAmount() + " " + money.getCurrencyName());
}
}
static class Person {
public String name;
Person(String name) {
this.name = name;
this.allMoney = new ArrayList<Money>();
//write your code here
/*Money Euro = new Money();
Money Ruble = new Money();
Money USD = new Money(); Money is an abstract class and cannot be instantiated*/
// create new instances of different currencies
allMoney.add(new Euro (5));
allMoney.add(new Ruble(4));
allMoney.add(new USD(3));
}
private List<Money> allMoney;
public List<Money> getAllMoney() {
return allMoney;
}
}
}