Try the fastest way to create flashcards
Question

Write a program that lets the user enter the loan amount and loan period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.

Solution

Verified
Answered 5 months ago
Answered 5 months ago
Step 1
1 of 3
import java.util.Scanner;
public class Main {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print(Loan Amount: );
        double loanAmount = input.nextDouble();
        System.out.print(Number of Years: );
        int years = input.nextInt();

        double interestRate, monthlyPayment, totalPayment;
        System.out.println(Interest Rate   Monthly Payment     Total Payment\n);
        for (double currentInterestRate = 5.0; currentInterestRate <= 8.0; 
              currentInterestRate += 0.125) {
            interestRate = currentInterestRate / 100 / 12;
            monthlyPayment = loanAmount * interestRate  / 
                             (1.0 - (1.0 / Math.pow(1 + interestRate, years * 12)));
            totalPayment = years * (monthlyPayment * 12);

            System.out.printf(%-4.3f%-11s%-20.2f%-8.2f\n, 
                    currentInterestRate, %, 
                    monthlyPayment, totalPayment);
        }
    }
}

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (6 more)David A. Patterson, John L. Hennessy
226 solutions
Introduction to Java Programming, Brief 8th Edition by Y. Daniel Liang

Introduction to Java Programming, Brief

8th EditionISBN: 9780132130790 (1 more)Y. Daniel Liang
500 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (3 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions

More related questions

1/4

1/7