Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Logo SIKSHAPATH Logo

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/Questions/Q 18408
Next
In Process
Pavanagg
  • 0
Pavanagg
Asked: June 1, 20222022-06-01T20:00:27+05:30 2022-06-01T20:00:27+05:30In: Computer Science

Loan Account Class: Create class LoanAccount. Use a static variable …

  • 0

Loan Account Class:
Create class LoanAccount. Use a static variable annuallnterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable principle indicating the amount the person is borrowing. Provide method: public double calculateMonthlyPayment(int numberOfPayments) to calculate the monthly payment by using the following formula:

double monthlyPayment = principle * (monthlyInterest/(1- Math.pow(1 + monthlylnterest, -numberOfPayments)));

where

monthly interest = annualInterestRate/12.

Provide a static method setAnnualinterestRate that sets the annualinterestRate to a new value. Set the initial loan amount (Principle) for a new loan through the constructor.

Write a program test class LoanAccount. Instantiate two LoanAccount objects, loan1 and loan2, with principle loan amounts of $5000.00 and $31000.00, respectively. Set annualinterestRate to 1%, then calculate the monthly payment for each loan for 36 months, 60 months, and 72 months and print the monthly payment amounts for both loans. Next, set the annualinterestRate to 5%, and output the same information again. Make sure your dollar amounts are displayed to two decimal places.

Put the code to test the class in the main method of the LoanAccount Class. The output of your program should look like the following:

Monthly payments for loan1 of $5000.00 and loan2 $31000.00 for 3, 5, and 6 year loans at 1% interest.

Loan     3 years    5 years    6 years

Loan1    141.04    85.47      71.58

Loan2    874.45   529.91    443.78

Monthly payments for loan1 of $5000.00 and loan2 $31000.00 for 3, 6, and 6 year loans at 6% interest.

Loan    3 years   5 years   6 years
Loan1   149.85   94.36     80.52
Loan2   929.10  585.01   499.25

  • 1 1 Answer
  • 141 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Answer

    • Voted
    • Oldest
    • Recent
    1. ADMIN 2
      2022-06-01T20:03:03+05:30Added an answer on June 1, 2022 at 8:03 pm
      import java.util.*; 
      public class LoanAccount{
      
      // A static variable to store the annual Interest rate 
      static double annualInterestRate; 
      // A private variable of type double to store the principle amount 
      private double principle;
      
      // Constructor of LoanAccount Class 
      LoanAccount(double p){
      principle = p; 
      }
      
      // The calculateMonthlyPayment() method computes the monthly payment
      // Provided the number of payments to be made for a given principle amount 
      public double calculateMonthlyPayment(int numberOfPayments){
      
      // The monthly interest rate is computed as annualInterestRate/12 
      double monthlyInterestRate = annualInterestRate/12;
      
      // Here computing the value of monthly payments using the below formula 
      double monthlyPayment = principle * ((monthlyInterestRate)/(1 - Math.pow(1 + monthlyInterestRate, -1*numberOfPayments)));
      
      // It returns the computed value of monthly payment 
      return monthlyPayment;
      }
      
      // Function to set the value of the annualInterestRate to a new rate 
      static void setAnnualInterestRate(double newRate){
      annualInterestRate = newRate;
      }
      
      // Main Method 
      public static void main(String[] args){
      
      // Created two instances of LoanAccount class with
      // Principle amount of 5000 for loan1 and 31000 for loan2 LoanAccount loan1 = new LoanAccount(5000); 
      LoanAccount loan2 = new LoanAccount(31000);
      
      // Test 1
      // Setting annualInterestRate to 1% or 0.01 setAnnualInterestRate(0.01);
      
      // Displaying the output in desired format
      System.out.println("Monthly payments for loan1 of $5000.00 and loan2 of $31000.00 for 3, 5 and 6 year loans at 1% interest."); System.out.println("Loan\t3 years\t5 years\t6 years");
      
      // Displaying the monthly payments of loan1 for the tenure for 36, 60 and 72 months 
      System.out.print("Loan1\t"); 
      System.out.print(String.format("%.2f\t", loan1.calculateMonthlyPayment(36)));
      System.out.print(String.format("%.2f\t", loan1.calculateMonthlyPayment(60))); 
      System.out.print(String.format("%.2f", loan1.calculateMonthlyPayment(72)));
      
      // Displaying the monthly payments of loan2 for the tenure for 36, 60 and 72 months 
      System.out.print("\nLoan2\t"); 
      System.out.print(String.format("%.2f\t", loan2.calculateMonthlyPayment(36))); 
      System.out.print(String.format("%.2f\t", loan2.calculateMonthlyPayment(60))); 
      System.out.print(String.format("%.2f", loan2.calculateMonthlyPayment(72)));
      
      // Test 2
      // Setting annualInterestRate to 5% or 0.05
      setAnnualInterestRate(0.05);
      
      // Displaying the output in desired format.
      System.out.println("\n\nMonthly payments for loan1 of $5000.00 and loan2 of $31000.00 for 3, 5 and 6 years loan at 1% interest."); 
      System.out.println("Loan\t3 years\t5 years\t6 years");
      
      // Displaying monthly payments for loan1 for the tenure for 36, 60 and 72 months
      System.out.print("Loan1\t"); 
      System.out.print(String.format("%.2f\t", loan1.calculateMonthlyPayment(36)));
      System.out.print(String.format("%.2f\t", loan1.calculateMonthlyPayment(60))); 
      System.out.print(String.format("%.2f", loan1.calculateMonthlyPayment(72)));
      System.out.print("\nLoan2\t");
      
      // Displaying monthly payments for loan2 for the tenure for 36, 60 and 72 months 
      System.out.print(String.format("%.2f\t", loan2.calculateMonthlyPayment(36)));
      System.out.print(String.format("%.2f\t", loan2.calculateMonthlyPayment(60))); 
      System.out.print(String.format("%.2f", loan2.calculateMonthlyPayment(72)));
        } 
      }
      • 0
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 139
    • Best Answers 65
    • Probability and Statistics NPTEL Assignment answers – Week 1
    • NPTEL Joy of Computing Using Python Week 2 Assignment Answers 2023
    • NPTEL Problem Solving Through Programming In C Assignment 2 Answers 2023
    • NPTEL Problem Solving Through Programming In C Assignment 1 Answers 2023
    • NPTEL Python for Data Science Assignment 1 Answers 2023

    Popular Questions

    • I'M ADMIN

      Internshala ethical hacking final test answers: Question sequence differs but ...

      • 6 Answers
    • AK

      You have a green lottery ticket, with ints a, b, ...

      • 4 Answers
    • mj

      Solve by Gauss Elimination Method 5x+y+z+w=4 ,x+7y+z+w=12 , x+y+6z+w=-5, x+y+z+4w=-6

      • 3 Answers

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow

    © 2021-2022 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.