Advertisement
Guest User

CIS 35A plssendhelp

a guest
Jan 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab1a {
  4.  
  5. public Lab1a() {
  6. }
  7. public void setValues() {
  8. double Principal = 0.0;
  9. double MonthlyPay = 0.0;
  10. double Interestrate = 0.0;
  11. double interest = 0.0;
  12. double balance = 0.0;
  13. double LoanAmount = 0.0;
  14. int Period = 0;
  15. int Years = 0;
  16. double monthlyInterestRate, temp;
  17. Scanner setValues = new Scanner(System.in);
  18.  
  19. System.out.println("Loan Amount:");
  20. LoanAmount = setValues.nextDouble();
  21. System.out.println("Number of Years:");
  22. Years = setValues.nextInt();
  23. Period = 12 * Years;
  24. System.out.println("Interest Rate");
  25. Interestrate = setValues.nextDouble();
  26. setValues.close();
  27. Principal = LoanAmount;
  28. monthlyInterestRate = ((Interestrate*0.01)/12);
  29. MonthlyPay=Principal*(monthlyInterestRate *(( Math.pow((1 + monthlyInterestRate), Period)) / ((Math.pow((1 + monthlyInterestRate), Period))-1)));
  30.  
  31. System.out.printf("MonthlyPay = %5.2f\n", MonthlyPay);
  32. balance = LoanAmount;
  33. // Source of for loop: Hint section on the textbook.
  34. for (int year=1;year<=Period;year++){
  35.  
  36. interest = ((Interestrate*0.01)/(12))*balance; /** monthly interest**/
  37. Principal = MonthlyPay - interest;
  38. balance = balance - Principal;
  39.  
  40. System.out.printf("Payment#:%dInterest:%4.2fPrincipal:%5.2fBalance:%5.2f\n",year,interest,Principal,balance);
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47. public static void main(String[] args) {
  48. Lab1a Lab1aObject = new Lab1a();
  49. Lab1aObject.setValues();
  50.  
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement