Question

In: Computer Science

Mortgage Calculator Create a form that allows you to enter in interest rate, monthly payment, principal...

Mortgage Calculator

Create a form that allows you to enter in interest rate, monthly payment, principal , and number of years. Your Java Servlet program then generates a table containing a row of output for each month of a mortgage. Your table should show Month number, New Principal, Interest Paid during the month. If the load is paid off, your table needs to properly stop.

*********************************** Sample Output *********************************

Interest Calculations

Calculating for:

interest rate/year =6

starting principal=10000

payment/month =1000

months =60

Month Number Principal Interest
1 9050.00 50.00
2 8095.25 45.25
3 7135.73 40.48
4 6171.40 35.68
5 5202.26 30.86
6 4228.27 26.01
7 3249.41 21.14
8 2265.66 16.25
9 1276.99 11.33
10 283.37 6.38

Last Payment = 284.79
This includes interest:1.42 **************************************************************************************

HINTS:

Take a look at the "RadioActive" servlet example in the notes. This application is similar to this homework. You can ignore the bar image part ... it's not part of this homework.

You will want to have a loop for the number of 12 * (Number of years). On each iteration of the loop, you will want to calculate the interest paid which is:

interestPaid = (newPrincipal * interest)/(12*100)

The 12 is because of 12 months in a year. The 100 is due to the fact that interest rates (like 6) are computed as 0.06 in interest calculations.

newPrincipal = newPrincipal + interestPaid - monthlyPayment

To get rid of the large number of decimal places that show up when you print a double, there is a format method in the String class that can help. Consider the following code (similar to the printf stuff in System.out):

String sPrinciple = String.format("%.2f", principal);

in Java Servlet

Solutions

Expert Solution

interest.html file

<html>
<head>
<title>Simple Interest</title>
</head>
<body>
<form action="servlet/Interest" method="post">
Interest Rates:<input type="number" name="rates"/><br/><br/>
Monthly Payment:<input type="number" name="Amount"/><br/><br/>
Principal:<input type="number" name="Principal"/><br/><br/>   
Number of Years:<input type="number" name="Years"/><br><br>
<input type="submit" value="Submit"/>
  
</form>
</body>
</html>

interest.java file

import java.io.*;  

import java.sql.*;  

import javax.servlet.ServletException;  

import javax.servlet.http.*;  

public class Interest extends HttpServlet {  

public void doPost(HttpServletRequest request, HttpServletResponse response)  

            throws ServletException, IOException {

response.setContentType("text/html");  

PrintWriter out = response.getWriter();  

Int r=request.getParameter("rates");  

Int a=request.getParameter("Amount");  

Float p=request.getParameter("Principal");  

Int y=request.getParameter("Years");  

try{  

Class.forName("oracle.jdbc.driver.OracleDriver");  

Connection con=DriverManager.getConnection(  

"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");  

  

PreparedStatement ps=con.prepareStatement(  

"insert into interestcalculation values(?,?,?,?)");  

  

ps.setInt(1,r);  

ps.setInt(2,a);  

ps.setFloat(3,p);  

ps.setInt(4,y);  

          

int i=ps.executeUpdate();  

if(i>0)  

out.print("You are successfully registered...");  

}

catch (Exception e2)

{

System.out.println(e2);

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("Interest Calculations");

out.println("Calculating for:);

out.println("Interest rates/Year"+ r);

out.println("Starting Principal"+ p);

out.println("Payment/month"+ a);

out.println("months"+ y);

float newPrincipal;

int InterestPaid, number;

newPrincipal=0.0;

number=0;

out.println(" MonthNumber"+ "Principal" +"Interest");

while(newPrincipal>m){

interestPaid= (newPrincipal*r)/(12*100);

newPrincipal= newPrincipal+InterestPaid-a;

out.println(number + newPrincipal + InterestPaid);

number++;

}

out.close();

}

public void destroy() { }

}

web.xml file

  1. <web-app>  
  2. <servlet>  
  3. <servlet-name>Interest</servlet-name>  
  4. <servlet-class>Interest</servlet-class>  
  5. </servlet>  
  6.   
  7. <servlet-mapping>  
  8. <servlet-name>Interest</servlet-name>  
  9. <url-pattern>/Interest</url-pattern>  
  10. </servlet-mapping>
  11. </web-app>  

Related Solutions

IN ANDROID STUDIO, you will create a mortgage calculator appthat allows the user to enter...
IN ANDROID STUDIO, you will create a mortgage calculator app that allows the user to enter a purchase price, down-payment amount, and an interest rate.Based on these values, the app should calculate the loan amount (purchase price minus down payment) and display the monthly payment for 10, 20, and 30-year loans.Allow the user to select a custom loan duration (in years) by using a SeekBar and display the monthly payment for that custom loan duration.Assignment deliverables (all in a ZIP...
Monthly Mortgage Payments The average monthly mortgage payment including principal and interest is 982 in the...
Monthly Mortgage Payments The average monthly mortgage payment including principal and interest is 982 in the United States. If the standard deviation is approximately 180 and the mortgage payments are approximately normally distributed, find the probabilities. Use a TI-83 Plus/TI-84 Plus calculator and round the answers to at least four decimal places. (a) (a)The selected monthly payment is more than $1400 (a)The selected monthly payment is more than 1400 P(Z>1400)= 2) Prison Sentences The average prison sentence for a person...
Find the monthly payment needed to amortize principal and interest for each fixed-rate mortgage for a...
Find the monthly payment needed to amortize principal and interest for each fixed-rate mortgage for a $220,000 at 4.5% interest for 30 years.
You wish to qualify for a $200,000 mortgage. Your monthly payment (principal and interest) must not...
You wish to qualify for a $200,000 mortgage. Your monthly payment (principal and interest) must not exceed 25% of your monthly income. Your monthly payment plus taxes and homeowner’s insurance must not exceed 28% of your monthly income. Your monthly payment, taxes, insurance, and other debt payments must not exceed 33% of your monthly income. The loan is for 30 years. Interest rates for these loans are 7%. Taxes and insurance are $250 per month and you have a $300...
The average monthly mortgage payment including principal and interest is $982 in the United States. If...
The average monthly mortgage payment including principal and interest is $982 in the United States. If the standard deviation is approximately $180 and the mortgage payments are approximately normally distributed, find the probability that a randomly selected monthly payment is: A. Between $800 and $1150 B. Less than $1,000
The monthly payment for a given loan pays the principal and the interest. The monthly interest...
The monthly payment for a given loan pays the principal and the interest. The monthly interest is computed by multiplying the monthly interest rate and the balance (the remaining principal). The principal paid for the month is therefore the monthly payment minus the monthly interest. Write a pseudocode and a Python program that let the user enter the loan amount, number of years, and interest rate, and then displays the amortization schedule for the loan (payment#, interest, principal, balance, monthly...
For this part you will need to use your calculator. What is the Monthly Mortgage Payment...
For this part you will need to use your calculator. What is the Monthly Mortgage Payment on a $125,000 Home with an 80% LTV with a 5% Interest Rate, 30-Year Fixed Rate Mortgage (Constant Payment Mortgage)? $536.82 What is the Monthly Mortgage Payment on a $125,000 Home with an 80% LTV with a 6% Interest Rate, 30-Year Fixed Rate Mortgage (Constant Payment Mortgage)? $599.55 How much more with the person with the mortgage in question #8 pay over the person...
With a conventional amortized mortgage loan, what is TRUE about each monthly principal and interest payment?...
With a conventional amortized mortgage loan, what is TRUE about each monthly principal and interest payment? a. The loan payment will go up each month. b. The portion used to pay interest increases. c. The portion used to pay interest decreases. d. The loan payment will go down each month.
Naomi has a 15 year mortgage on her house. Her monthly principal and interest payment is...
Naomi has a 15 year mortgage on her house. Her monthly principal and interest payment is $1,373. Her annual insurance is $1,388 and her annual property taxes are $1,996. Find her adjusted monthly payment of principal, interest, taxes, and insurance (PITI). Please show step by step. Thank you
Consider a 30-year mortgage with an interest rate of 10% compounded monthly and a monthly payment...
Consider a 30-year mortgage with an interest rate of 10% compounded monthly and a monthly payment of $850. (1) Calculate the principal. (2) How much of the principal is paid the first, 5th, 20th and last year? (3) How much interest is paid the first, 5th, 20th and last year year? (4) What is the total amount of money paid during the 30 years? (5) What is the total amount of interest paid during the 30 years? (6) What is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT