mportJava.text.DecimalFormat;ImportJava.util.Scanner; Public classfulijisuanqi02 {StaticScanner Scanner =NewScanner (system.in); StaticDecimalFormat DF =NewDecimalFormat ("# # #0.0000"); Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println ("1. Compound interest calculation;"); System.out.println ("2. Simple interest calculation;"); System.out.println ("3. Principal calculation;"); System.out.println ("4. Age calculation. "); System.out.println ("5. Rate of return calculation:"); System.out.println ("6. Total asset value calculation:"); System.out.println ("Please select:"); intK =Scanner.nextint (); Switch(k) { Case1: Fulijisuan (); Break; Case2: Danlijisuan (); Break; Case3: Benjinjisuan (); Break; Case4: Nianxianjisuan (); Break; Case5: Baochoulvjisuan (); Break; Case6: Leijizichanjisuan (); Break; default: Break; } } Private Static voidLeijizichanjisuan () {//TODO auto-generated Method StubSystem.out.println ("Please enter the principal:"); DoubleP =scanner.nextdouble (); System.out.println ("Please enter the annual investment amount:"); DoubleT =scanner.nextdouble (); System.out.println ("Please enter your investment life:"); intn =Scanner.nextint (); System.out.println ("Please enter the investment rate:"); Doublei =scanner.nextdouble (); for(intj = 0;j < n;j++) {P= P * (1 +i); P= P +T; } DoubleF = P-T;
String f = Df.format (f); System.out.println ("Asset value is:" +f); } Private Static voidBaochoulvjisuan () {//TODO auto-generated Method StubSystem.out.println ("Please enter the principal:"); DoubleP =scanner.nextdouble (); System.out.println ("Please enter the end value of compounding:"); DoubleF =scanner.nextdouble (); System.out.println ("Please enter the age limit:"); intn =Scanner.nextint (); Doublei = Math.pow ((f/p), (1.0/n))-1;
String f = df.format (i); System.out.println ("Interest rate is:" +f); } Private Static voidNianxianjisuan () {//TODO auto-generated Method StubSystem.out.println ("Please enter the principal:"); DoubleP =scanner.nextdouble (); System.out.println ("Please enter the interest rate:"); Doublei =scanner.nextdouble (); System.out.println ("Please enter the end value of compounding:"); DoubleF =scanner.nextdouble (); intn = (int) (Math.log (f/p)/Math.log (1 +i)); System.out.println ("Years are:" +N); } Private Static voidBenjinjisuan () {//TODO auto-generated Method StubSystem.out.println ("Please enter compounding end value:"); DoubleF =scanner.nextdouble (); System.out.println ("Please enter the interest rate:"); Doublei =scanner.nextdouble (); System.out.println ("Please enter the age limit:"); intn =Scanner.nextint (); DoubleP; P= F/math.pow (1 +I, N); String P=Df.format (P); System.out.println ("Principal is:" +p); } Private Static voidDanlijisuan () {//TODO auto-generated Method StubSystem.out.println ("Please enter the principal:"); DoubleP =scanner.nextdouble (); System.out.println ("Please enter the interest rate:"); Doublei =scanner.nextdouble (); System.out.println ("Please enter the age limit:"); intn =Scanner.nextint (); DoubleF; F= P * (1 + i *N); String F=Df.format (F); System.out.println ("Simple interest Final value is:" +f); } Private Static voidFulijisuan () {System.out.println ("Please enter the principal:"); DoubleP =scanner.nextdouble (); System.out.println ("Please enter the interest rate:"); Doublei =scanner.nextdouble (); System.out.println ("Please enter the age limit:"); intn =Scanner.nextint (); DoubleF; F= P * MATH.POW (1 +I, N); String F=Df.format (F); System.out.println ("Compounding end value is:" +f); }}
The program I use the Java language to compile, the number of lines of code is about 150 lines, the workload of about one hours.
This improvement is expected to be completed in 20 minutes, and the number of lines of code will probably be 20-30 lines.
This modification mainly adds two functions, one is to calculate the rate of return, and the other is to calculate the investment in the same time each year to invest a certain amount, the two difficulties are mainly in the process of calculation, which is the difficulty of this procedure, there is insufficient place is not to make the interface.
The workload also exceeded expectations, mainly because the calculation of the cost of a relatively large time, and other places are the same as before, mainly is the method of calculation is different.
Compound Interest Calculation 2.0