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.
3 ответов
+ 7
Алина Конькова ,
> what kind of issue do you have?
> please also link your code here
+ 6
Алина Конькова ,
and what is the issue?
+ 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;
}
}