A simple Java Loan program

Source: Internet
Author: User

The code is as follows:

Calculate loan
Package Classdemo;
Import Javax.swing.joptionpane;public class Computeloan {
public static void Main (string[] args) {
User Input Loan Total
String loanstring = Joptionpane.showinputdialog ("Please enter the total amount of the loan:");
Double loanamount = double.parsedouble (loanstring);

User input Annual interest rate
String annualintereststr = Joptionpane.showinputdialog ("Please enter the loan annual interest rate (e.g. 7.00):");
Double annualinterestrate = double.parsedouble (ANNUALINTERESTSTR);
Calculate monthly interest Rate
Double monthlyinterestrate = annualinterestrate/1200;

User input loan years
String numberofyearsstr = Joptionpane.showinputdialog ("Please enter the length of the loan:");
int numberofyears = Integer.parseint (NUMBEROFYEARSSTR);

Calculate monthly repayment Amount and total repayment amount
Double monthlypayment = Loanamount * Monthlyinterestrate/(1-1/Math.pow (1 + monthlyinterestrate, Numberofyears * 12)) ;
Double totalpayment = monthlypayment * numberofyears;

Format payment as two digits after the decimal point, using a downward rounding method
monthlypayment = (int) (monthlypayment * 100)/100.0;
totalpayment = (int) (totalpayment * 100)/100.0;

Output results, totalpayment and Monthlypayment
String output = "Monthly repayment amount:" + monthlypayment + "\ n Total Repayment amount:" + totalpayment;
Joptionpane.showmessagedialog (null, Output);
}
}

A simple Java Loan program

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.