Created
August 19, 2021 08:27
-
-
Save mherman22/de0d7722907fa991a1ca5eafc7717799 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package myJourney; | |
import java.text.NumberFormat; | |
import java.util.Scanner; | |
public class Calculator { | |
public static void main(String[] args) { | |
final byte MONTHS_IN_A_YEAR = 12; | |
final byte PERCENT = 100; | |
Scanner scanner = new Scanner (System.in); | |
System.out.print("Principal: "); | |
int principal = scanner.nextInt(); | |
System.out.print("Annual Interest Rate: "); | |
float annual_interest_rate = scanner.nextFloat(); | |
float monthly_interest = annual_interest_rate / PERCENT / MONTHS_IN_A_YEAR; | |
System.out.print("Period (years) : "); | |
byte period = scanner.nextByte(); | |
int number_of_payments = period * MONTHS_IN_A_YEAR; | |
double mortgage = principal | |
* (monthly_interest * Math.pow(1 + monthly_interest,number_of_payments)) | |
/ (Math.pow(1 + monthly_interest, number_of_payments) - 1); | |
System.out.println("Mortgage : "+ NumberFormat.getCurrencyInstance().format(mortgage)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just practice for primitive types ,and operators