Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab1a {
- public Lab1a() {
- }
- public void setValues() {
- double Principal = 0.0;
- double MonthlyPay = 0.0;
- double Interestrate = 0.0;
- double interest = 0.0;
- double balance = 0.0;
- double LoanAmount = 0.0;
- int Period = 0;
- int Years = 0;
- double monthlyInterestRate, temp;
- Scanner setValues = new Scanner(System.in);
- System.out.println("Loan Amount:");
- LoanAmount = setValues.nextDouble();
- System.out.println("Number of Years:");
- Years = setValues.nextInt();
- Period = 12 * Years;
- System.out.println("Interest Rate");
- Interestrate = setValues.nextDouble();
- setValues.close();
- Principal = LoanAmount;
- monthlyInterestRate = ((Interestrate*0.01)/12);
- MonthlyPay=Principal*(monthlyInterestRate *(( Math.pow((1 + monthlyInterestRate), Period)) / ((Math.pow((1 + monthlyInterestRate), Period))-1)));
- System.out.printf("MonthlyPay = %5.2f\n", MonthlyPay);
- balance = LoanAmount;
- // Source of for loop: Hint section on the textbook.
- for (int year=1;year<=Period;year++){
- interest = ((Interestrate*0.01)/(12))*balance; /** monthly interest**/
- Principal = MonthlyPay - interest;
- balance = balance - Principal;
- System.out.printf("Payment#:%dInterest:%4.2fPrincipal:%5.2fBalance:%5.2f\n",year,interest,Principal,balance);
- }
- }
- public static void main(String[] args) {
- Lab1a Lab1aObject = new Lab1a();
- Lab1aObject.setValues();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement