You are on page 1of 1

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafundamentsl;
import java.util.Scanner;
import java.text.NumberFormat;

/**
*
* @author Caduur
*/
public class JavaFundamentsl {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
final byte MONTHS_IN_YEAR = 12;
final byte PERCENT = 100;
Scanner scanner = new Scanner(System.in);
System.out.println("principal: ");
int principal = scanner.nextInt();
System.out.println("Annual Interest Rate: ");
float annualInterest = scanner.nextFloat();
float monthlyInterest = annualInterest / PERCENT / MONTHS_IN_YEAR;

System.out.println("Period (Years): ");


byte years = scanner.nextByte();
int numberOfPayments = years * MONTHS_IN_YEAR;

double mortgage = principal * (monthlyInterest *Math.pow(1 +


monthlyInterest, numberOfPayments)
/(Math.pow(1 + monthlyInterest, numberOfPayments)-1));
String mortgageFormatted =
NumberFormat.getCurrencyInstance().format(mortgage);
System.out.println("Mortgage: " + mortgageFormatted);

You might also like