package de.codegym.task.task14.task1417;
import java.util.ArrayList;
import java.util.List;
/*
Währungen
*/
public class Solution {
public static void main(String[] args) {
Person paul = new Person("Paul"); //<----(3) and also here?
for (Money money : paul.getAllMoney()) { // (4) <-- so why should i do it like that then?
System.out.println(paul.name + " hat eine Notfallreserve von " + money.getAmount() + " " + money.getCurrencyName());//<<right now it doesnt find symbol getCurrencyName
}
}
static class Person {
public String name;
private List<Money> allMoney;
Person(String name) { //<---- (2) then i need to initialize it here no?
this.name = name;
this.allMoney = new ArrayList<Money>(); //<--- (1) if i add a list to the constructor
//schreib hier deinen Code
allMoney.add(new Euro());
allMoney.add(new Ruble());
allMoney.add(new USD());
}
public List<Money> getAllMoney() {
return allMoney;
}
}
abstract class Money {
private double amount;
public double getAmount(){
return amount;
}
}
class Euro extends Money {
public Euro(double amount){
super.amount = amount;
}
public String getCurrencyName(){
return "EUR";
}
}
class Ruble extends Money {
public Ruble(double amount){
super.amount = amount;
}
public String getCurrencyName(){
return "RUB";
}
}
class USD extends Money {
public USD(double amount){
super.amount = amount;
}
public String getCurrencyName(){
return "USD";
}
}
}