Posting this again because day limit has run out. Again I really need help with this. This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's and JSP 3rd Edition. The program used is NetBeans IDE 8.2. I need help modifying or adding some code. I will post the code I was told to open that needs to be modified below.
Exercise 9-3 Use JSTL to add a table to the Future Value application.
In this exercise, you’ll use JSTL to add a table to the Future Value application showing the value of a series of monthly investments at the end of each year.
Review the project.
- Start NetBeans and open the project named ch09_ex3_futureValue that’s in the more_ex_starts directory.
- Open the FutureValueServlet class. Note that the code in the doPost method has been modified to create a list of calculation objects, one for each year starting at one and going up to the number of years entered by the user. Also, note that it stores an attribute named calculations in the request.
Modify the code.
- Open the index.jsp file. Then, modify it so it uses the JSTL choose tags instead of JSTL if tags.
- Open the result.jsp file. Then, modify it so it presents a table that displays the value of the investment for each year up to the year the user entered. To do this, you can use a JSTL forEach tag. When you’re done, the user interface should look something like this:

- Note that the Investment Amount, Yearly Interest Rate, and Number of Years fields are no longer working correctly. This is because the application stores multiple calculations instead of a single calculation.
- Fix the application so the second page displays the Investment Amount, Yearly Interest Rate, and Number of Years fields again. There are several ways to do this. Choose the way that you think works best.
Here is the code that I was informed to open. I need the above requirements to be met. This is all done in Java. Please I really need help with this thank you very much!
FutureValueServlet.java
package murach.fv;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import murach.business.Calculation;
@WebServlet("/calculate")
public class FutureValueServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// get parameters from the request
String investmentString = request.getParameter("investment");
String interestRateString = request.getParameter("interest_rate");
String yearsString = request.getParameter("years");
// validate the parameters
String url;
String message;
double investment = 0;
double interestRate = 0;
int years = 0;
try {
investment = Double.parseDouble(investmentString);
interestRate = Double.parseDouble(interestRateString);
years = Integer.parseInt(yearsString);
message = "";
url = "/result.jsp";
} catch (NumberFormatException e) {
message = "Please enter a valid number in all three text boxes.";
url = "/index.jsp";
}
request.setAttribute("message", message);
// Create a calculation object for each year
List<Calculation> calculations = new ArrayList<Calculation>();
for (int i = 1; i <= years; i++) {
Calculation calculation = new Calculation();
calculation.setMonthlyInvestmentAmount(investment);
calculation.setYearlyInterestRate(interestRate);
calculation.setYears(i);
calculations.add(calculation);
}
// Store calculations list in calculations object
request.setAttribute("calculations", calculations);
request.setAttribute("years", years);
request.setAttribute("message", message);
request.getSession().setAttribute("investment", investment);
request.getSession().setAttribute("interestRate", interestRate);
getServletContext()
.getRequestDispatcher(url)
.forward(request, response);
}
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
}
index.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="header.jsp" %>
<section>
<h1>Future Value Calculator</h1>
<p><i>${message}</i></p>
<form action="calculate" method="post">
<label>Investment Amount:</label>
<c:if test="${investment != null}">
<input type="text" name="investment"
value="${investment}"/><br>
</c:if>
<c:if test="${investment == null}">
<input type="text" name="investment"
value="${calculation.monthlyInvestmentAmount}"/><br>
</c:if>
<label>Yearly Interest Rate:</label>
<c:if test="${interestRate != null}">
<input type="text" name="interest_rate"
value="${interestRate}"/><br>
</c:if>
<c:if test="${interestRate == null}">
<input type="text" name="interest_rate"
value="${calculation.yearlyInterestRate}"/><br>
</c:if>
<label>Number of Years:</label>
<input type="text" name="years"
value="${calculation.years}"/><br>
<label> </label>
<input type="submit" value="Calculate"/><br>
</form>
</section>
<%@include file="footer.jsp" %>
result.jsp
<%@include file="header.jsp" %>
<section>
<h1>Future Value Calculator</h1>
<label>Investment Amount:</label>
<span>${calculation.monthlyInvestmentAmountCurrencyFormat}</span><br />
<label>Yearly Interest Rate:</label>
<span>${calculation.yearlyInterestRate}</span><br />
<label>Number of Years:</label>
<span>${calculation.years}</span><br />
<label>Future Value:</label>
<span>${calculation.futureValueCurrencyFormat}</span><br />
<label> </label>
<span><a href="javascript:void(0)"> </section>
<%@include file="footer.jsp" %>
Please I really need help with this if a Java expert can help me I would appreciate it.
Future Value Calculator Year Investment Amount: Yearly Interest Rate: Number of Years: Value $1,219.68 $2,476.46 $3,771.46 $5,105.85 $6,480.83 Return to Calculator © 2014, Mike Murach and Associates