exchange method
Buys or sells currencyA
- If money of currencyA is being passed, it's being sold and currencyB is being returned
- If money of currencyB is being passed, currencyA is being bought returned
If none of above, Exception is thrown
Implementation
Money exchange(
/// Amount to exchange
Money amount,
) {
if (amount.currency == currencyA) {
return Money(_round(amount.amount * rateSell), currencyB);
}
if (amount.currency == currencyB) {
return Money(_round(amount.amount / rateBuy), currencyA);
}
throw Exception('This currency is not supported by this constructor');
}