0

Create a TMoney class

Create a TMoney class to work with monetary amounts. The amount should stored as a dollar equivalent. Implement the methods of adding / withdrawing money supply, specifying the required amount in hryvnia, and determining the dollar exchange rate at which the amount in hryvnia will increase by 100. Keep the dollar exchange rate in a separate field.

17th Jan 2023, 10:16 AM
Алина Конькова
3 ответов
+ 7
Алина Конькова , > what kind of issue do you have? > please also link your code here
17th Jan 2023, 10:37 AM
Lothar
Lothar - avatar
+ 6
Алина Конькова , and what is the issue?
17th Jan 2023, 11:52 AM
Lothar
Lothar - avatar
+ 1
class TMoney { private double dollarEquivalent; private double exchangeRate; public TMoney(double initialAmount, double exchangeRate) { this.dollarEquivalent = initialAmount; this.exchangeRate = exchangeRate; } public void AddMoney(double amountInHryvnia) { dollarEquivalent += amountInHryvnia / exchangeRate; } public void SubtractMoney(double amountInHryvnia) { dollarEquivalent -= amountInHryvnia / exchangeRate; } public double GetExchangeRateForHryvniaIncrease(double increaseInHryvnia) { return (increaseInHryvnia + (increaseInHryvnia / exchangeRate)) / increaseInHryvnia; } public double GetDollarEquivalent() { return dollarEquivalent; } }
17th Jan 2023, 10:59 AM
Алина Конькова