对于成熟度,我认为这个公式是错误的,它给出了错误的答案。我只想要它每月一次。成熟度案例已经结束了。任何帮助都将不胜感激。
package interest;
import java.util.Scanner;
public class Interest {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
Scanner whatKindPeriod = new Scanner(System.in);
double principle;
double rate;
double period;
double result;
double periodNumber;
String type;
String matOrSimp;
double matResult;
System.out.println("find maturity or simple interest? for simple interest enter simple, and for maturity enter maturity");
matOrSimp = userInput.next();
switch (matOrSimp) {
case "simple":
System.out.println("please enter the principle:");
principle = userInput.nextDouble();
System.out.println("Enter the rate:");
rate = userInput.nextDouble();
System.out.println("enter period:");
period = userInput.nextDouble();
System.out.println("is it daily, monthly or yearly?");
type = userInput.next();
switch (type) {
case "yearly":
result = (principle * rate * period) / 100;
System.out.println("your simple interest is: $" + result);
case "daily":
double daily = period / 365;
result = (principle * rate * daily) / 100;
System.out.println("your simple interest is: $" + result);
case "monthly":
double monthly = period / 12;
result = (principle * rate * monthly) / 100;
System.out.println("your simple interest is: $" + result);
SimpleInterest interest = new SimpleInterest(principle, rate, period);
}
case "maturity":
System.out.println("please enter the principle:");
principle = userInput.nextDouble();
System.out.println("Enter the rate:");
rate = userInput.nextDouble();
System.out.println("enter time of invesment:");
period = userInput.nextDouble();
double monthly = period / 12;
matResult = (principle * (1 + rate * monthly));
System.out.println("result is:" + matResult);
}
}
}发布于 2019-11-28 14:39:24
到期日的公式包括一个复合利率,因此不是:
principle * (1 + rate * monthly)一般情况下,您应该使用:
principle * Math.pow(1 + periodicRate, compoundingPeriods)因此,对于您的每月复利,以下方法计算所需的到期日:
double computeMaturity(double principle, double monthlyRate, double months) {
return principle * Math.pow(1 + monthlyRate, months);
}最后要注意的是,年利率必须以分数形式给出,而不是百分比(10%利率= 0.1 monthlyRate)。
希望这能有所帮助。
https://stackoverflow.com/questions/59080847
复制相似问题