Question: Write an HTML form that prompts the user to enter loan amount, interest rate, and number of years, as shown in Figure 37.28a. Clicking the

Write an HTML form that prompts the user to enter loan amount, interest rate, and number of years, as shown in Figure 37.28a. Clicking the Compute Loan Payment button invokes a servlet to compute and display the monthly and total loan payments, as shown in Figure 37.28b. Use the Loan class given in Listing 10.2, Loan.java, to compute the monthly and total payments.

Frercke3/_S- Mora refox Inix Morita Firefex Jox| EdR w Hetory Bookmarks Toot

Data from Listing 10.2,

Listing 10.2 Loan.java
1 public class Loan {
2 private double annualInterestRate;
3 private int numberOfYears;
4 private double loanAmount;
5 private java.util.Date loanDate;
6
7 /** Default constructor */
8 public Loan() {
9 this(2.5, 1, 1000);
10 }
11

12 /** Construct a loan with specified annual interest rate,
13 number of years, and loan amount
14 */
15 public Loan(double annualInterestRate, int numberOfYears,
16 double loanAmount) {
17 this.annualInterestRate = annualInterestRate;
18 this.numberOfYears = numberOfYears;
19 this.loanAmount = loanAmount;
20 loanDate = new java.util.Date();
21 }
22
23 /** Return annualInterestRate */
24 public double getAnnualInterestRate() {
25 return annualInterestRate;
26 }
27
28 /** Set a new annualInterestRate */
29 public void setAnnualInterestRate(double annualInterestRate) {
30 this.annualInterestRate = annualInterestRate;
31 }
32
33 /** Return numberOfYears */
34 public int getNumberOfYears() {
35 return numberOfYears;
36 }
37
38 /** Set a new numberOfYears */
39 public void setNumberOfYears(int numberOfYears) {
40 this.numberOfYears = numberOfYears;
41 }
42
43 /** Return loanAmount */
44 public double getLoanAmount() {
45 return loanAmount;
46 }
47
48 /** Set a new loanAmount */
49 public void setLoanAmount(double loanAmount) {
50 this.loanAmount = loanAmount;
51 }
52
53 /** Find monthly payment */
54 public double getMonthlyPayment() {
55 double monthlyInterestRate = annualInterestRate / 1200;
56 double monthlyPayment = loanAmount * monthlyInterestRate / (1 –
57 (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)));
58 return monthlyPayment;
59 }
60
61 /** Find total payment */
62 public double getTotalPayment() {
63 double totalPayment = getMonthlyPayment() * numberOfYears * 12;
64 return totalPayment;
65 }
66
67 /** Return loan date */
68 public java.util.Date getLoanDate() {
69 return loanDate;
70 }
71 }

Frercke3/_S- Mora refox Inix Morita Firefex Jox| EdR w Hetory Bookmarks Toot Hop w Hory oknaris Jooe t ONetp:/ocacst.80 umpute Loan+Payment + Exercke75 kocahost:3060Fchapter37servietexerasoExercse37 05.emi ve E- cooge 8 ocahost:8080/chaptera7servietecercike/Exercise3_O57barnount-150000 Compute Loan Payment Loan Amount: 150000.0 Loan Amount 150000 Aunual Interest Rate 7.85 Number of Years 16 Annual Interest Rate: 7.85 Number of Years: 15 Monthly Payment: 1420.5191824522967 Total Payment: 255693.45284141344 Compute Lean Payment RasetI (a) (b) FIGURE 37.28 The servlet computes the loan payment.

Step by Step Solution

3.27 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Loan Amount Interest Rate Number of Years The above form prompts the user to enter the loan amount i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Java Programming and Data Structure Questions!