Hallo,
Ik kom er even niet uit bij een opdracht voor school. De opdracht is:
Ziet iemand misschienwaar de fout ligt, want ik kom er maar niet uit.
Ik kom er even niet uit bij een opdracht voor school. De opdracht is:
zelf heb ik dit geprobeerd:"Write a method to compute future investment value at a given interest rate for a specified number of years. The future investment is determined using the following formula:
futureInvestmentValue =
investmentAmount x ((1 + monthlyInterestRate)tot de macht(years*12))
Use the following method declaration:
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int Years)
For example, futureInvestmentValue(10000, 0.05, 5) returns 12833.59.
Hint: use Math.pow(a, b) method to compute a raised to the power of b."
De uitkomst is bij mij '186791.85894122993' in plaats van '12833.59'.public class Three
{
public static void main(String[] args)
{
System.out.print("Enter your investment amount: ");
double investmentAmount = MyInput.readDouble();
System.out.print("Enter your monthly interest rate: ");
double monthlyInterestRate = MyInput.readDouble();
System.out.print("Enter a number of years: ");
int years = MyInput.readInt();
double fiv = futureInvestmentValue (investmentAmount, monthlyInterestRate, years);
System.out.println(fiv);
}
public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int years)
{
double number = investmentAmount * Math.pow((1 + monthlyInterestRate),(years * 12));
return number;
}
}
Ziet iemand misschienwaar de fout ligt, want ik kom er maar niet uit.