Question

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:

Future Value Calculator Year Investment Amount: Yearly Interest Rate: Number of Years: Value $1,219.68 $2,476.46 $3,771.46 $5

  • 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>&nbsp;</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>&nbsp;</label>
<span><a href="index.jsp">Return to Calculator</a></span>
</section>
<%@include file="footer.jsp" %>

Please I really need help with this if a Java expert can help me I would appreciate it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find below JSP file code with screenshot. Let me know if you have any query.

------------------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">

<br /><label>Investment Amount:</label>
<c:choose>
<c:when test="${investment != null}">
<input type="text" name="investment" value="${investment}"/>
</c:when>
<c:otherwise>
<input type="text" name="investment" value="${calculation.monthlyInvestmentAmount}"/>
</c:otherwise>
</c:choose>

<br /><label>Yearly Interest Rate:</label>
<c:choose>
<c:when test="${interestRate != null}">
<input type="text" name="interest_rate" value="${interestRate}"/>
</c:when>
<c:otherwise>
<input type="text" name="interest_rate" value="${calculation.yearlyInterestRate}"/>
</c:otherwise>
</c:choose>

<br /><label>Number of Years:</label>
<input type="text" name="years" value="${calculation.years}"/>
<br />
<label>&nbsp;</label>
<input type="submit" value="Calculate"/>
<br />
</form>
</section>
<%@include file="footer.jsp" %>

Murachs Java Servlets and JSP x + - x E → C localhost:8084/ch09_ex3_futureValue/index.jsp Future Value Calculator Investment

-----------------result.jsp-------------------- Supported with java 7 and EL 3.0

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="header.jsp" %>
<section>
<h1>Future Value Calculator</h1>
<label>Investment Amount:</label>
${calculations.stream().map(calculation -> calculation.monthlyInvestmentAmount).sum()}
<br />
<label>Yearly Interest Rate:</label>
${interestRate}
<br />
<label>Number of Years:</label>
${years}
<br />
<label>Future Value:</label>
${calculations.stream().map(calculation -> calculation.futureValue).sum()}
<br />
<label>&nbsp;</label>
<table>
<tr>
<th>Year</th>
<th>Value</th>
</tr>
<c:forEach items="${calculations}" var="calculation">
<tr>
<td>${calculation.years}</td>
<td>${calculation.monthlyInvestmentAmount}</td>
</tr>
</c:forEach>

</table>
<span>
<a href="index.jsp">Return to Calculator</a>
</span>
</section>
<%@include file="footer.jsp" %>

Murachs Java Servlets and JSP X + - 0 X f = c localhost:8084/ch09_ex3_futureValue/calculate Future Value Calculator 7500.0 1

Add a comment
Know the answer?
Add Answer to:
Posting this again because day limit has run out. Again I really need help with this....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this exercise, you’ll modify the Future Value Calculator application to include a header and footer....

    In this exercise, you’ll modify the Future Value Calculator application to include a header and footer. Review the project Open the header.jsp file and note that it contains the code necessary for the start of an HTML page including the opening html, head, and body tags, the title for the web page, and a link including the CSS file. Open the footer.jsp file and note that includes a copyright notice and the closing body and html tags. Modify the code...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

  • I need help, I have my page set up, I just need help with some aesthetics,...

    I need help, I have my page set up, I just need help with some aesthetics, and getting the clear button to work, and get a popup when they click submit that says success along as all fields are filled out correctly. Any help would be fantastic. <html lang="en"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="styleSheet.css" /> <title>2020-2021 Student-Athlete Registration Form - Weber State University</title> </head> <body> <header> <h1>WEBER STATE UNIVERSITY</h1> </header> <div class="link"> <ul> <li><a href="page 1.html"><span class="text">Home</span></a></li> </ul> </div>...

  • Hello! I am to create a .js file that allows the paragraph on the bottom of...

    Hello! I am to create a .js file that allows the paragraph on the bottom of the page to update with what the user enters. I need to modify the given HTML to recognize the javascript file that I am to make from scratch. The HTML file and other details are below: Use the given HTML to add functionality to an interactive form that generates an invitation to volunteers for an event. The file will have the following invitation message...

  • Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum...

    Develop the Change Calculator application In this exercise, you’ll create an application that displays the minimum number of quarters, dimes, nickels, and pennies that make up the number of cents specified by the user. Without the use of a JavaScript Library (for coins). 1.      Open the HTML and JavaScript files below: 2.      In the JavaScript file, note that three functions are supplied. The $ function. The start of a calculateChange function. And an onload event handler that attaches the calculateChange...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after ...

    need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after the decimal point. Process and sample run: a) Function 1: A void function that uses parameters passed by reference representing the name of a data file to read data from, amount of principal in an investment portfolio, interest rate (any number such as 5.5 for 5.5% interest rate, etc.) , number of times the interest is compounded, and the number of years the money is...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based...

    Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...

  • Hey I really need some help asap!!!! I have to take the node class that is...

    Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT