liangm20

Question 73

Oct 7th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. Question 73:
  2.  
  3. Pseudocode:
  4.  
  5. 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
  6. 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.)
  7. 3. Output all of the following calculations according to format (i.e. decimal notation, percent notation, etc.)
  8.  
  9. Syntax:
  10.  
  11. import java.util.*;
  12. import java.text.*;
  13. public class math
  14. {
  15. public static void main(String[] args)
  16. {
  17. start();
  18. math(scanneraIR(), scannernOY(), scannerM());
  19. }
  20. public static void start()
  21. {
  22. 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...");
  23. Scanner corn = new Scanner(System.in);
  24. String cornhub = corn.next();
  25. System.out.println("Hi, " + cornhub + "!");
  26. }
  27. public static void math(double aIR, double nOY, double M) //calculations for the problem
  28. {
  29. aIR /= 12;
  30. double mIR = aIR;
  31. aIR *= 12;
  32. double monthPay = (mIR*M)/(1-(1/((Math.pow((1+mIR),(12*nOY))))));
  33. double totalPay = 12*nOY*monthPay;
  34. double overPay = (totalPay-M);
  35. double overPayp = 100-((M/totalPay)*100);
  36. printer(mIR, aIR, monthPay, totalPay, overPay, overPayp);
  37. }
  38. public static double scanneraIR() //scanner for interest rate
  39. {
  40. Scanner aIR = new Scanner(System.in);
  41. System.out.print("Type in your monthly interest rate: ");
  42. double x = aIR.nextDouble();
  43. x /= 100;
  44. return x;
  45. }
  46. public static double scannernOY() //scanner for number of years
  47. {
  48. Scanner nOY = new Scanner(System.in);
  49. System.out.print("Type in your number of years that the mortgage will be held: ");
  50. double y = nOY.nextInt();
  51. return y;
  52. }
  53. public static double scannerM() //scanner for the mortgage
  54. {
  55. Scanner nMA = new Scanner(System.in);
  56. System.out.print("Type in your number representing the mortgage amount borrowed from the bank: ");
  57. double z = nMA.nextDouble();
  58. return z;
  59. }
  60. public static void printer(double mIR, double aIR, double monthPay, double totalPay, double overPay, double overPayp) //output
  61. {
  62. System.out.printf("The total payment is: $%.2f", totalPay); // print with two decimal places
  63. System.out.println();
  64. System.out.printf("The amount of money paid in interest is: $%.2f", overPay); // print with unlimited decimal
  65. System.out.println();
  66. System.out.printf("The over payment percentage is: %.2f", overPayp); // print overpayment
  67. System.out.print("%");
  68. System.out.println();
  69. System.out.printf("The monthly payment is: $%.2f", monthPay);
  70. System.out.println();
  71. mIR *= 100;
  72. aIR *= 100;
  73. System.out.printf("The monthly interest rate is: %.2f", mIR);
  74. System.out.print("%");
  75. System.out.println();
  76. System.out.printf("The annual interest rate is: %.2f", aIR);
  77. System.out.print("%");
  78. System.out.println();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment