Compounding calculator (software engineering) and JUnit test ——— Guo Zhihao

Source: Internet
Author: User

Calculation: 1. The principal is 1 million, the interest rate or the return on investment is 3%, the investment period is 30, then the interest income obtained after 30 years is calculated by compounding formula: 1,000,000x (1+3%) ^30

Customer proposed:

2. If according to simple interest calculation, how much is the principal and interest?

3. If a pension of $3 million is to be raised after 30, the average annual return is 3%, what is the amount of principal that must be invested now?

4 The interest rate is so low, compounding profits are so strong, if take 1 million yuan to buy the annual return rate of 10% of the stock, if all goes well, too long, 1 million yuan becomes 2 million yuan?

5. If I want to turn $1 million into $2 million within 10 years, how much should I find the investment tool to help me achieve my goals? If you want to double the principal after 5 years, how much should the rate of return be at least?

6. If the savings of $30,000 are to be invested annually, with a return of 3% per annum, and then a new round of investment in these Benli and annuities, what will the total value of assets be after 30 years? What if we switch to 3000 a month?

7. Do you write programs that allow customers to operate at will? What is the reaction of accidentally entering data and accidentally doing unconventional operating procedures?

Mutual viewing of the program operation.

8. If a bank loan of 100,000 yuan, the annual interest rate of 6.5%, the term is 10, then the monthly equal and principal repayment amount? (For compounding conditions, inferior amount repayment amount)

Package Fuli;

Import java.util.*;
Import java.math.*;
Import java.text.*;

Import Org.omg.CORBA.PUBLIC_MEMBER;

public class Gzh {

public int Nianxian (double p,double f,double i) {

int n= (int) ((Math.log (F)/Math.log (1 + i))-(Math.log (P)/Math
. log (1 + i));
return N;

}

public static void Main (string[] args) {
TODO auto-generated Method Stub
System.out.println ("Welcome to use Compounding Calculator! --by Guo Zhihao ");
/*
* Compounding formula: f=p* (1+i) N (second square) F: Compounding end P: Principal I: Interest rate N: An integer multiple of the acquisition time of interest rate
*/
Gzh BB = new Gzh ();
Scanner input = new Scanner (system.in);
System.out.println ("Compounding calculator:");
System.out.println ("Principal by 1 compound interest (simple interest) by 2 years according to 3 interest rate according to 4 year gold final value by 5 periodic coupon Press 6");
int num = Input.nextint ();
DecimalFormat df1 = new DecimalFormat ("#.00");
Seeking Principal

if (num = = 1) {
System.out.println ("Please enter compounding End value:");
Double F = input.nextdouble ();
System.out.println ("Please enter annual interest rate:");
Double i = input.nextdouble ();
System.out.println ("Please enter the number of years of deposit:");
int N = Input.nextint ();
Double P = F/math.pow (1 + i, N); Principal
System.out.println ("The required principal is:" + Df1.format (P));
}
Seeking compounding (simple interest)
else if (num = = 2) {
SYSTEM.OUT.PRINTLN ("Please input deposit:");
Double P = input.nextdouble ();
System.out.println ("Please enter annual interest rate:");
Double i = input.nextdouble ();
System.out.println ("Please enter the number of years of deposit:");
int N = Input.nextint ();
Double D = P * (1 + i * N); Simple interest
SYSTEM.OUT.PRINTLN ("Simple Interest Final value:" + Df1.format (D));
System.out.println ("Please enter the annual compounding Number:");
int m = Input.nextint ();
Double F = P * (Math.pow ((1 + i/m), N * m)); Compounding
SYSTEM.OUT.PRINTLN ("Compounding End Value:" + Df1.format (F));
}
The required years
else if (num = = 3) {
SYSTEM.OUT.PRINTLN ("Please input deposit:");
Double P = input.nextdouble ();
System.out.println ("Please enter compounding End value:");
Double F = input.nextdouble ();
System.out.println ("Please enter annual interest rate:");
Double i = input.nextdouble ();
int N1 = (int) bb. Nianxian (F, I, P);
int N = (int) ((Math.log (F)/Math.log (1 + i))-(Math.log (P)/Math
. log (1 + i));
System.out.println ("The required years are:" +N1);
} else if (num = = 4) {
SYSTEM.OUT.PRINTLN ("Please input deposit:");
Double P = input.nextdouble ();
System.out.println ("Please enter compounding End value:");
Double F = input.nextdouble ();
System.out.println ("Please enter the number of years of deposit:");
int N = Input.nextint ();
Double i = (Math.pow (f/p, 1.0/n))-1;
SYSTEM.OUT.PRINTLN ("Annual interest rate is:" + i);
System.out.println ("is the principal n years after the N-fold?" Yes please press 1 ");
int up = Input.nextint ();
if (up = = 1) {
System.out.println ("Please enter a few years later:");
int n = input.nextint ();
System.out.println ("doubling:");
int f = input.nextint ();
Double I = 72.0/(n/f); 72 Law
SYSTEM.OUT.PRINTLN (n + "years after the principal doubling of the annual interest rate is at least:" + Df1.format (I));
}
if (Up! = 1) {
System.out.println ("Welcome again!") ");

}
} else if (num = = 5) {
SYSTEM.OUT.PRINTLN ("Investment by year by 1 per month by 2");
int number = Input.nextint ();
if (number = = 1) {
System.out.println ("Principal to be invested:");
Double P = input.nextdouble ();
SYSTEM.OUT.PRINTLN ("obtained annual interest rate return:");
Double i = input.nextdouble ();
System.out.println ("Length of investment (years):");
Double N = Input.nextint ();

Double F = p * (Math.pow (1 + i, N)-1)/I;
System.out.println ("The end value of an annuity by year is:" + Df1.format (F));
}
if (number = = 2) {
System.out.println ("Principal to invest:");
Double P = input.nextdouble ();
System.out.println ("obtained annual interest rate return:");
Double i = input.nextdouble ();
System.out.println ("Investment Years:");
Double N = Input.nextint ();
Double F = P * (Math.pow (1 + i/12.0, N *)-1)/(I/12);
System.out.println ("The end value of the monthly annuity is:" + Df1.format (F));
}
if (number! = 1 | | | number! = 2) {
System.out.println ("Input Error! ");
}
} else if (num = = 6) {
System.out.println ("Principal to Loan:");
Double P = input.nextdouble ();
System.out.println ("Loan annual interest Rate: (years)");
Double i = input.nextdouble ();
System.out.println ("loan Term (years):");
Double N = input.nextdouble ();
Double H = P
* (((I/12) * (Math.pow (1 + I/12, n *))/(Math.pow (
1 + I/12, n *)-1));
System.out.println ("Monthly repayment required:" + Df1.format (H));
} else {
System.out.println ("Input Error! ");
}
}



}

JUnit Test

The code hasn't been optimized yet, and the next step is to finish, other tests are the same as this, first list one!

Summary: From the beginning to the present, constantly emerging problems, and constantly solve problems, the work slowly formed, more and more energetic, This is the charm of programming!

Compounding calculator (software engineering) and JUnit test ——— Guo Zhihao

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.