0317 Compound Interest Calculation 3.0

Source: Internet
Author: User

1 ImportJava.util.Scanner;2 3  Public classText {4      Public Static voidMain (string[] args) {5         6 7          Do {8Scanner Scanner =NewScanner (system.in);9System.out.println ("");TenSystem.out.print ("Please select (0 for exit, 1 for the principal and interest, 2 for the principal, 3 for the investment, 4 for the value of the asset after n years):"); One             intNumber1 =scanner.nextint (); A  -             if(Number1 = = 1) { -System.out.print ("Please enter the principal:"); the                 DoubleMoney =scanner.nextdouble (); -System.out.print ("Please enter annual interest rate:"); -                 DoubleRate =scanner.nextdouble (); -System.out.print ("Please enter the Age:"); +                 intYear =scanner.nextint (); -                  +System.out.print ("Please select (1 for compounding, 2 for simple interest):"); A                 intNumber2 =scanner.nextint (); at                  -                 if(Number2 = = 1) { -                      for(inti = 1; I <= year; i++) { -Money = (1 + rate) *Money ; -                     } -System.out.println ("deposit" + year + "years after the compound interest is calculated as follows:" + (Double) (Math.Round (money*100)/100.0)); in                      -                 } to                 if(Number2 = = 2) { +Money = money + Money * Rate *Year ; -System.out.println ("deposit" + year + "years after the simple interest calculation of principal and interest is:" + (Double) (Math.Round (money*100)/100.0)); the                 } *                  $                 Panax Notoginseng  -             } the  +             if(Number1 = = 2) { ASystem.out.print ("Please enter the principal and interest:"); the                 DoubleMoney =scanner.nextdouble (); +System.out.print ("Please enter annual interest rate:"); -                 DoubleRate =scanner.nextdouble (); $System.out.print ("Please enter the Age:"); $                 intYear =scanner.nextint (); -                  -System.out.print ("Please select (1 for compounding, 2 for simple interest):"); the                 intNumber2 =scanner.nextint (); -                 Wuyi                 if(Number2 = = 1) { the                     Doublenum = 1; -                      for(inti = 1; I <= year; i++) { Wunum = num * (1 +Rate ); -                     } AboutMoney = Money * (1/num); $System.out.println ("Compound interest is required to deposit the principal:" + (Double) (Math.Round (money*100)/100.0)); -                 } -                 if(Number2 = = 2) { -Money = Money * (1/(1 + rate *Year )); ASYSTEM.OUT.PRINTLN ("Simple interest calculation requires deposit of the principal:" + (Double) (Math.Round (money*100)/100.0)); +                 } the  -             } $             if(Number1 = = 3) { the  theSystem.out.print ("Please Enter investment amount:"); the                 DoubleMoney1 =scanner.nextdouble (); theSystem.out.print ("Please enter the amount of harvest:"); -                 DoubleMoney2 =scanner.nextdouble (); in  theSystem.out.print ("Please select (1 to calculate time, 2 to calculate interest rate):"); the                 intNumber2 =scanner.nextint (); About                  the                 if(Number2 = = 1) { theSystem.out.print ("Please enter annual interest rate:"); the                     DoubleRate =scanner.nextdouble (); +                     DoubleYear ; -Year = Logarithm.log (money2/money1,1+Rate ); theYear =Math.ceil (year);BayiSystem.out.println ("Number of years to be deposited:" +Year ); the}Else if(Number2 = = 2) { theSystem.out.print ("Please enter the Age:"); -                     intYear =scanner.nextint (); -                     DoubleRate ; theRate = Math.pow (money2/money1, 1.0/year)-1; theSystem.out.println ("The required annual interest rate is:" + (Double) (Math.Round (rate*10000)/10000.0)); the                 } the             } -              the             if(Number1 = = 4){ theSystem.out.print ("Please enter the annual investment amount:"); the                 DoubleMoney1 =scanner.nextdouble ();94System.out.print ("Please enter annual interest rate:"); the                 DoubleRate =scanner.nextdouble (); theSystem.out.print ("Please enter the Age:"); the                 intYear = Scanner.nextint ();DoubleMoney2=0;98                  for(inti=1;i<=year;i++){ About                      -money1=money1+Money2;101Money2=money1* (1 +Rate );102                     103                 }104The total assets of SYSTEM.OUT.PRINTLN (year+ "year") are: "+ (Double) (Math.Round (money2*100)/100.0)); the             }106 107             if(Number1 = = 0) {108SYSTEM.OUT.PRINTLN ("Thank you for using!" " );109System.exit (0); the                 111             } the} while(true);113     } the}
1  Public class logarithm {2     Static  Public Double log (double double base) {3         return Math.log (value)/Math.log (base); 4          5      }67 }

0317 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.