Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /** This program will print out information regarding a loan and also capture the output of a file.
  2. * Class: CST183
  3. * Due 10/19/17
  4. * Name: Taylen White
  5. */
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. public class LoanCalc{
  10.  
  11. public static void main(String args[]) {
  12.  
  13. // declare variables
  14. double monthlyPayment;
  15. int loanTerm;
  16. double loanAmount;
  17. int interestRate;
  18.  
  19. loanTerm = getLoanTerm();
  20. if (loanTerm < 1 || loanTerm > 30) {
  21. JOptionPane.showMessageDialog(null, "Your loan term must be within the range of 1 - 30 years. ");
  22. }
  23.  
  24. loanAmount = getLoanAmount();
  25. if (loanAmount < 0 || loanAmount > 1000000) {
  26. JOptionPane.showMessageDialog(null, "Your loan amount must be within the range of 0 - $1,000,000. ");
  27. }
  28.  
  29. interestRate = getInterestRate();
  30. if (interestRate < 1 || interestRate > 8) {
  31. JOptionPane.showMessageDialog(null, "Your interest rate must be from 1 - 8%. ");
  32. }
  33. calculateMonthlyPayment(loanAmount, interestRate, loanTerm);
  34. JOptionPane.showMessageDialog(null, "Your monthly payment will be" + monthlyPayment );
  35. }
  36.  
  37. public static int getLoanTerm()
  38. {
  39. String inputStringLoanTerm = JOptionPane.showInputDialog(null, "Please input your desired loan term.(Between 1 and 30 years) ");
  40. return Integer.parseInt(inputStringLoanTerm);
  41.  
  42. }
  43.  
  44. public static double getLoanAmount()
  45. {
  46. String inputStringLoanAmount = JOptionPane.showInputDialog(null, "Please input your desired loan amount. (Between 0 and $1,000,000) ");
  47. return Integer.parseInt(inputStringLoanAmount);
  48.  
  49. }
  50.  
  51. public static int getInterestRate()
  52. {
  53. String inputStringInterestRate = JOptionPane.showInputDialog(null, "Please input your desired interest rate. (Between 1 - 8%) ");
  54. return Integer.parseInt(inputStringInterestRate);
  55.  
  56. }
  57.  
  58. public static double calculateMonthlyPayment(double principal, int monthlyInterestRate, int numberOfMonths)
  59. {
  60. double monthlyPayment = principal / (1-(1 + monthlyInterestRate)- numberOfMonths / monthlyInterestRate);
  61. return monthlyPayment;
  62. }
  63. //public static double CreateAmortTable()
  64. // {
  65.  
  66. // return amortTable;
  67. // }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement