如何从单利及其等式中获取到期值

How to get the maturity value from simple interest and the equation for it

对于成熟度,我认为公式是错误的,给出了错误的答案。我只想要每月一次。到期案例在最后。任何帮助将不胜感激。

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);

        }

    }
}

成熟期公式包括复利,因此代替:

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)。

Complete code on GitHub

希望这对您有所帮助。