0318-Compounding 3

Source: Internet
Author: User

ImportJava.text.DecimalFormat;ImportJava.util.Scanner; Public classFulijisuan { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println ("Welcome to use Compounding Calculator! "); /*Compounding formula: f=p* (1+r) ^n * F: Compound End Value * P: Principal * r: Interest rate * N: An integer multiple of interest rate acquisition time*/Scanner Scanner=NewScanner (system.in); System.out.print ("Compounding calculator: Calculate simple interest and compound interest Press 1, calculate the principal please press 2, stock please press 3, the rate of return please press 4, the total value of assets please press 5, monthly equal and principal repayment please press 6:"); intnum=Scanner.nextint (); DecimalFormat DF1=NewDecimalFormat ("#.00"); if(num==1){            DoubleF; System.out.print ("Please enter the principal P:"); DoubleP =scanner.nextdouble (); System.out.print ("Please enter the number of years to deposit N:"); intN =Scanner.nextint (); System.out.print ("Please enter interest rate R:"); DoubleR =scanner.nextdouble (); F=p+p*n*R; System.out.println ("Simple interest End value is f:" +Df1.format (F)); F=0; System.out.print ("Please enter the number of compounding times:"); Doublem =scanner.nextdouble (); F=p* (Math.pow (1+r/m), nm)); System.out.println ("End value of compound interest is f:" +Df1.format (F)); }        if(num==2){             DoubleH=1, P; System.out.print ("Please enter the end value of compound interest F:"); DoubleF =scanner.nextdouble (); System.out.print ("Please enter the number of years to deposit N:"); intN =Scanner.nextint (); System.out.print ("Please enter interest rate R:"); DoubleR =scanner.nextdouble (); P=f/math.pow (1 +R, N); System.out.println ("The principal should be P:" +Df1.format (P)); }        if(num==3){            DoubleN = 1; System.out.print ("Please enter the principal P:"); Doublep=scanner.nextdouble (); System.out.print ("Please enter the final value f:"); Doublef=scanner.nextdouble (); System.out.print ("Please enter the rate of return R:"); DoubleR =scanner.nextdouble (); N=(int) ((Math.log (F)/math.log (1+r))-(Math.log (P)/math.log (1 +R)); System.out.println ("Deposit time is N:" +N); }        if(num==4){            DoubleR= 1; System.out.print ("Please enter the principal P:"); Doublep=scanner.nextdouble (); System.out.print ("Please enter the final value f:"); Doublef=scanner.nextdouble (); System.out.print ("Please enter the number of years to deposit N:"); intN =Scanner.nextint (); R=math.pow (f/p,1d/N); System.out.println ("The rate of return should be r:" +Df1.format (R)); }        if(num==5) {System.out.println ("Annual input Please press 51, monthly input Please press 52:"); intNumber=Scanner.nextint (); if(number==51){                DoubleF= 1; System.out.print ("Please enter the annual principal P:"); Doublep=scanner.nextdouble (); System.out.print ("Please enter interest rate R:"); Double R=scanner.nextdouble (); System.out.print ("Please enter the number of years to deposit N:"); intN =Scanner.nextint (); F=p* (Math.pow ((1+r), N)-1)/R; System.out.println ("The end value of an annual investment is F:" +Df1.format (F)); }            if(number==52) {System.out.print ("Please enter the monthly principal P:"); Doublep=scanner.nextdouble (); System.out.print ("Please enter interest rate R:"); Double R=scanner.nextdouble (); System.out.print ("Please enter the number of years to deposit N:"); intN =Scanner.nextint (); Doublef=p* (Math.pow (1+r/12.0, n*12)-1)/(R/12); System.out.println ("The final value of the monthly investment is F:" +Df1.format (F)); }            }                                                if(num==6){            DoubleP1=1,f=1; System.out.print ("Please enter the borrowing amount P:"); Doublep=scanner.nextdouble (); System.out.print ("Please enter annual interest rate R:"); Double R=scanner.nextdouble (); System.out.print ("Please enter the repayment period N:"); intN =Scanner.nextint ();  for(inti=1;i<=n;i++) {F=p+ (P*R) *N; } p1=f/12; System.out.println ("Monthly equal and principal repayment:" +Df1.format (p1)); }    }}

0318-Compounding 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.