forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputeLoan.java
More file actions
executable file
·42 lines (40 loc) · 1.48 KB
/
ComputeLoan.java
File metadata and controls
executable file
·42 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* */ package ch02;
/* */
/* */ import java.util.Scanner;
/* */
/* */ public class ComputeLoan
/* */ {
/* */ public static void main(String[] args) {
/* 8 */ Scanner input = new Scanner(System.in);
/* */
/* */
/* 11 */ System.out.print("Enter yearly interest rate, for example 8.25: ");
/* 12 */ double annualInterestRate = input.nextDouble();
/* */
/* */
/* 15 */ double monthlyInterestRate = annualInterestRate / 1200.0D;
/* */
/* */
/* 18 */ System.out.print("Enter number of years as an integer, for example 5: ");
/* */
/* 20 */ int numberOfYears = input.nextInt();
/* */
/* */
/* 23 */ System.out.print("Enter loan amount, for example 120000.95: ");
/* 24 */ double loanAmount = input.nextDouble();
/* */
/* */
/* */
/* 28 */ double monthlyPayment = loanAmount * monthlyInterestRate / (1.0D - 1.0D / Math.pow(1.0D + monthlyInterestRate, (numberOfYears * 12)));
/* 29 */ double totalPayment = monthlyPayment * numberOfYears * 12.0D;
/* */
/* */
/* 32 */ System.out.println("The monthly payment is $" + ((int)(monthlyPayment * 100.0D) / 100.0D));
/* */
/* 34 */ System.out.println("The total payment is $" + ((int)(totalPayment * 100.0D) / 100.0D));
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch02/ComputeLoan.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/