Compound Interest Calculation 3.0

Source: Internet
Author: User

ImportJava.util.Scanner; Public classMoney { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); System.out.println ("Please enter calculation method: 1. Simple interest Calculation 2. Compounding 3. Principal calculation 4. Stock term calculation 5. Interest rate calculation 6. Gross asset value calculation");//Select calculation Method        intChoose =Scanner.nextint (); if(choose = = 1) {//1. Simple Interest Calculation modeDanlijisuan (scanner); } Else if(choose = = 2) {//2. Compound Interest Calculation modeFulijisuan (scanner); } Else if(choose = = 3) {//3. Principal calculation modeBenjinjisuan (scanner); } Else if(choose = = 4) {//4. Stock calculation modeGupiaoqixian (scanner); } Else if(choose = = 5) {//5. Interest rate calculation ModeLilvjisuan (scanner); } Else if(Choose = = 6) {Zichanzongzhi (scanner);    } scanner.close (); }    //gross asset calculation model    Private Static voidZichanzongzhi (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Please enter the principal:"); P=scanner.nextdouble (); System.out.println ("Please enter the annual investment amount:"); DoubleT =scanner.nextdouble (); System.out.println ("Please enter your investment life:"); N=Scanner.nextint (); System.out.println ("Please enter the interest rate:"); I=scanner.nextdouble (); //Calculation         for(intj = 0; J < N; J + +) {P= P * (1 +i); P= P +T; } F= P-T; System.out.println ("Asset value is:" +F); }    //interest rate calculation mode    Private Static voidLilvjisuan (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Enter the Principal:"); P=scanner.nextdouble (); System.out.println ("Enter Deadline:"); N=scanner.nextdouble (); System.out.println ("Input principal value:"); F=scanner.nextdouble (); //Calculationi = F/(P *N); System.out.println ("Interest rate is:" +i); }    //Stock term calculation mode    Private Static voidGupiaoqixian (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Enter the Principal:"); P=scanner.nextdouble (); System.out.println ("Enter interest rate:"); I=scanner.nextdouble (); System.out.println ("Input principal value:"); //CalculationF =scanner.nextdouble (); N= (f-P)/(I *P); System.out.println ("The term is:" +N); }    //principal calculation Mode    Private Static voidBenjinjisuan (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Input principal value:"); F=scanner.nextdouble (); System.out.println ("Enter interest rate:"); I=scanner.nextdouble (); System.out.println ("Enter Deadline:"); N=scanner.nextdouble (); P= F/(1 + i *N); System.out.println ("The principal should be invested:" +P); }    //Compound Interest Calculation mode    Private Static voidFulijisuan (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Enter the Principal:"); P=scanner.nextdouble (); System.out.println ("Enter interest rate:"); I=scanner.nextdouble (); System.out.println ("Enter Deadline:"); N=scanner.nextdouble (); F= P * Math.pow ((1 +i), N); System.out.println ("Principal and Interest Value:" + math.round (F * 100)/100.0); }    //Simple Interest Calculation mode    Private Static voidDanlijisuan (Scanner Scanner) {DoubleP; Doublei; DoubleN; DoubleF; System.out.println ("Enter the Principal:"); P=scanner.nextdouble (); System.out.println ("Enter interest rate:"); I=scanner.nextdouble (); System.out.println ("Enter Deadline:"); N=scanner.nextdouble (); F= p + p * I *N; System.out.println ("Principal and Interest Value:" + math.round (F * 100)/100.0); }

The program is developed in the Java language, and the tool is the eclipse 4.5,JDK version is 1.8, the code line number of 135 lines, originally expected to take 1 hours, did not expect to use 1.5 hours, mainly or for the code looks more beautiful, the code refactoring a bit, each model has its own method, improve the code of reading and reuse.

This modification increases the interest rate calculation mode and the total asset value calculation mode, and the lack of user interface has not been made easy to use.

Compound Interest Calculation 3.0

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.