Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

RequiredC A single Java class with a main method and multiple other methods. Use

ID: 3881273 • Letter: R

Question

RequiredC A single Java class with a main method and multiple other methods. Use the Eclipse IDE Scenario/Information: For most home loans, there are three main values that represent the state of the: the principal (total amount loaned), interest rate (usually stored as annual rate), and total term (in years) that the homeowner has until the loan should be fully repaid. If these three values are known, then other characteristics about the loan can be calculated. For example: Monthly Rate Annual Rate/12 ·Total Months Total Term * 12 Monthly Payment Principal Monthly Rate /(1-( + Monthly Rate)Total Moaths)) onthly PaymenPrincipal * Month! What to do: Write a new simple Java program with Eclipse using a main method and several other methods that will take some initial loan values and calculate the monthly rate, total months, and monthly payment. Your main method can initialize basic loan values, but it must call a different method for each calculation and a separate method to output results to the console. You should output the results to the Eclipse console window. Be sure to run, test and debug your program before submission. https://gyazo.com/4aa72cb398f44bb2b55aOef5a1e7fb5b May be dumb, but I know how to do it in the main method. I don't know how to do it with multiple methods. Please help

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//LoanDetails.java

import java.util.Scanner;

public class LoanDetails {

      public static void main(String[] args) {

            double loanAmt = 0 ;

            int numYears = 0;

            double interestRate=0;

            Scanner scanner = new Scanner(System.in);

            try {

                  System.out.println("Enter loan amount:");

                  loanAmt = Double.parseDouble(scanner.nextLine());

                  System.out.println("Enter annual interest rate:");

                  interestRate = Double.parseDouble(scanner.nextLine());

                  System.out.println("Enter number of years:");

                  numYears = Integer.parseInt(scanner.nextLine());

                  if(loanAmt<=0 || interestRate<=0 || numYears<=0){

                        /**

                        * Invalid loan details

                        */

                        System.out.println("Values cannot be zero or negative");

                        System.exit(1);

                  }

                  /**

                  * calculating the number of months

                  */

                  int numMonths=getNumberOfMonths(numYears);

                  /**

                  * Calculating the monthly interest rate

                  */

                  double monthlyInterest=getMonthlyInterest(interestRate);

                  /**

                  * calculating the monthly payment rate

                  */

                  double monthlyPayment = getMonthlyPayment(loanAmt, numMonths, monthlyInterest);

                  /**

                  * Total amount to be paid including the interest

                  */

                  double total=getTotalAmountToBePaid(monthlyPayment, numMonths);

                  /**

                  * printing all data

                  */

                  printData(monthlyPayment, total, numMonths);

                 

                 

            } catch (NumberFormatException e) {

                  System.out.println("Invalid input");

            }

           

           

           

      }

      /**

      * method to find the monthly payment rate, by passing loan amount, total number of months

      * and monthly interest rate

      */

      static double getMonthlyPayment(double loanAmt, int numMonths,

                  double monthlyInterest) {

            /**

            * Applying the formula to find the monthly payment rate

            *

            * P = L[c(1 +c)^n]/[(1 + c)^n - 1]

            *

            * (fixed monthly payment (P) required to fully amortize a loan of L

            * dollars over a term of n months at a monthly interest rate of c)

            */

            double monthlyPaymentRate = loanAmt * monthlyInterest

                        * (Math.pow(1 + monthlyInterest, numMonths))

                        / (Math.pow(1 + monthlyInterest, numMonths) - 1);

            return monthlyPaymentRate;

      }

      /**

      * method to calculate the monthly interest, by passing annual interest rate

      * @param interestRate - rate of interest in percentage

      */

      static double getMonthlyInterest(double interestRate){

            double monthlyInterest = ((interestRate / 100) / 12);

            return monthlyInterest;

      }

      /**

      * method to calculate the total amount to be paid

      * @param monthlyRate- calculated monthly payment

      * @param numberOfMonths- number of months

      * @return

      */

      static double getTotalAmountToBePaid(double monthlyRate, int numberOfMonths){

            return (double) monthlyRate*numberOfMonths;

      }

      /**

      * method to get the number of months, given as years

      * @param numberOfYears - number of years

      * @return

      */

      static int getNumberOfMonths(int numberOfYears){

            return numberOfYears*12;

      }

      /**

      * method to print the data

      */

      static void printData(double monthlyPayment,double total,int numMonths){

            System.out.printf("You have to pay a total of $%.2f ", total);

            System.out.printf("Monthly payment: $%.2f ",monthlyPayment);

            System.out.println("Total Months: "+numMonths);

      }

}

/*OUTPUT*/

Enter loan amount:

125000

Enter annual interest rate:

7.02

Enter number of years:

3

You have to pay a total of $138988.09

Monthly payment: $3860.78

Total Months: 36

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote