Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Question 73:
- Pseudocode:
- 1. Create 3 scanners that prompt user for a double annual interest rate, amount of years mortgage will be held, and the number representing the mortgage amount borrowed from the bank
- 2. Copy the formulas from the Java Illuminated eBook and plug in the user input from the scanners for the formula and calculate the monthly payment; also calculate the other prompts needed (i.e. over pay, total pay, over pay percent, etc.)
- 3. Output all of the following calculations according to format (i.e. decimal notation, percent notation, etc.)
- Syntax:
- import java.util.*;
- import java.text.*;
- public class math
- {
- public static void main(String[] args)
- {
- start();
- math(scanneraIR(), scannernOY(), scannerM());
- }
- public static void start()
- {
- System.out.println("Welcome to Shaurya's, Michelle's, Max's, and Owen's Mortgage Calculator for noobs. Type in your name and press enter...");
- Scanner corn = new Scanner(System.in);
- String cornhub = corn.next();
- System.out.println("Hi, " + cornhub + "!");
- }
- public static void math(double aIR, double nOY, double M) //calculations for the problem
- {
- aIR /= 12;
- double mIR = aIR;
- aIR *= 12;
- double monthPay = (mIR*M)/(1-(1/((Math.pow((1+mIR),(12*nOY))))));
- double totalPay = 12*nOY*monthPay;
- double overPay = (totalPay-M);
- double overPayp = 100-((M/totalPay)*100);
- printer(mIR, aIR, monthPay, totalPay, overPay, overPayp);
- }
- public static double scanneraIR() //scanner for interest rate
- {
- Scanner aIR = new Scanner(System.in);
- System.out.print("Type in your monthly interest rate: ");
- double x = aIR.nextDouble();
- x /= 100;
- return x;
- }
- public static double scannernOY() //scanner for number of years
- {
- Scanner nOY = new Scanner(System.in);
- System.out.print("Type in your number of years that the mortgage will be held: ");
- double y = nOY.nextInt();
- return y;
- }
- public static double scannerM() //scanner for the mortgage
- {
- Scanner nMA = new Scanner(System.in);
- System.out.print("Type in your number representing the mortgage amount borrowed from the bank: ");
- double z = nMA.nextDouble();
- return z;
- }
- public static void printer(double mIR, double aIR, double monthPay, double totalPay, double overPay, double overPayp) //output
- {
- System.out.printf("The total payment is: $%.2f", totalPay); // print with two decimal places
- System.out.println();
- System.out.printf("The amount of money paid in interest is: $%.2f", overPay); // print with unlimited decimal
- System.out.println();
- System.out.printf("The over payment percentage is: %.2f", overPayp); // print overpayment
- System.out.print("%");
- System.out.println();
- System.out.printf("The monthly payment is: $%.2f", monthPay);
- System.out.println();
- mIR *= 100;
- aIR *= 100;
- System.out.printf("The monthly interest rate is: %.2f", mIR);
- System.out.print("%");
- System.out.println();
- System.out.printf("The annual interest rate is: %.2f", aIR);
- System.out.print("%");
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment