Compounding 5.0 (change to Java version) and unit test

Source: Internet
Author: User

//Because the C language version is not convenient unit test, so changed to Java version, part of the code is as follows:
ImportJava.util.Scanner; Public classfuli{ Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); System.out.println ("\ n Compound interest calculated by 1\n simple interest calculated by 2\n calculated according to the 3\n calculation time according to 4\n calculate your interest rate according to 5\n calculation Benli and investment according to 6\n calculation of equal and principal repayment by 7\n\n); intC=Scanner.nextint (); if(c==1) {System.out.println ("Enter your principal:"); DoubleMoney =NewScanner (system.in). nextdouble (); System.out.println ("Enter your desired annual interest rate:"); DoubleRate =NewScanner (system.in). nextdouble (); System.out.println ("Enter your desired deposit period (years):"); intYear =NewScanner (system.in). Nextint (); Doubleresult=money* (1+rate*Year ); System.out.println ("The result is:" +result); } if(c==2) {System.out.println ("Enter the amount you need to raise:"); DoubleFuturemoney =NewScanner (system.in). nextdouble (); System.out.println ("Enter your desired deposit period (years):"); intYear =NewScanner (system.in). Nextint (); System.out.println ("Enter your desired interest rate:"); DoubleRate =NewScanner (system.in). nextdouble (); Doubleresult = futuremoney/(1+rate*Year ); System.out.println ("The principal you need to deposit is:" +result); } } }

I also carried out the unit tests for these two functions. The first is the test of compound interest calculation. The running results and test results are as follows:

Then the second Test, which is about raising pensions, runs the results and tests the results as follows:

Compounding 5.0 (change to Java version) and unit test

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.