Introduction to Java Programming, Brief Version 10th edition Complete Programmin
ID: 3568618 • Letter: I
Question
Introduction to Java Programming, Brief Version 10th edition
Complete Programming Exercise 16.13 Comparing Loans with Various Interest Rates on page 671.
Chapter 16.
(Financial application: compare loans with various interest rates) Write a pro- gram 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. Here is a sample run: (Compare loans with various interest rates) Rewrite Programming Exercise 5.21 to create a GUI, as shown in Figure 16.41b. Your program should let the user enter the loan amount and loan period in the number of years from text fields, and it should display the monthly and total payments for each interest rate starting from 5 percent to 8 percent. with increments of one -eighth. in a text area.Explanation / Answer
09 import java.util.Scanner; 10 11 public class Exercise04_21 { 12 13 public static void main(String[] args) { 14 Scanner input = new Scanner(System.in); 15 16 System.out.print("Enter loan amount: "); 17 double loanAmount = input.nextDouble(); 18 19 System.out.print("Enter number of years: "); 20 int numOfYears = input.nextInt(); 21 22 double annualInterestRate = 5; 23 double monthlyInterestRate = annualInterestRate / 1200; 24 double monthlyPayment = loanAmount * monthlyInterestRate 25 / (1 - (Math.pow(1 / (1 + monthlyInterestRate), numOfYears * 12))); 26 double totalPayment = monthlyPayment * 12 * numOfYears; 27 28 System.out.println("Loan Amount: " + loanAmount); 29 System.out.println("Number of Years: " + numOfYears); 30 System.out.println(); 31 System.out.println("Interest Rate Monthly Payment Total Payment"); 32 33 double i = 5.0; 34 int lastMonth = numOfYears * 12; 35 int month = 1; 36 37 while (iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.