Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Homework 2 (Loops)

1. Interests.java: 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 annual interest rate     starting from 5% to 8%, with an increment of 1/8. Use double values for all the amounts and percentages. Hint:

monthlyInterestRate = annualInterestRate / 1200;

monthlyPayment = loanAmount * monthlyInterestRate / (1 - (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));

totalPayment = monthlyPayment * numberOfYears * 12;

For example:

Loan amount: 10000

Number of years: 5

Interest Rate

5%

5. 125%

5.25%

7(..).(.)875%

8.0%

Monthly Payment

188.71

189.29

189.85

202.16

202.76

Total Payment

11322.74

11357.13

11391.59

12129.97

12165.83

2. Pyramid.java:  Write a nested for loop that inputs the number of lines and prints powers of 2 as a pyramid pattern shown in the following example. You may assume that the user enters any number of lines up to 13.

Enter the number of lines: 8

Output:

1

1    2    1

1     2    4    2    1

1     2     4    8    4    2    1

1     2     4     8   16    8    4    2    1

1     2     4     8    16   32   16    8    4    2    1

1    2     4     8    16    32   64   32   16    8    4    2    1

1    2    4     8    16    32    64  128   64   32   16    8    4    2    1