1 answer

Posting this again because day limit has run out. Again I really need help with this....

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

Answers

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

.

Similar Solved Questions

1 answer
D. A patient is placed IT ULJIM 2.30. A physician sees a patient in his office in the morning, then again in the ea...
d. A patient is placed IT ULJIM 2.30. A physician sees a patient in his office in the morning, then again in the early afternoon, at which time he sends the patient to the hospital in observation status Later that day he visits the patient in the hospital and admits him as a full inpatient What E/M ...
1 answer
Mailings Review View Help Tell me what you want to do AaBbCcDd AaBbCcDd AaBbC AaBbCcD 1...
Mailings Review View Help Tell me what you want to do AaBbCcDd AaBbCcDd AaBbC AaBbCcD 1 Normal 1 No Spac.. Heading 1 Heading 2 Title Subtitle S Styles Paragraph Read and respond to the following paragraph and give your opinion? Skin color has been proven to evolve from our ancestor's dark skin. ...
1 answer
Describe the skewness and kurtosis with the distribution graph. X (income) No. of persons Cumulative frequency...
describe the skewness and kurtosis with the distribution graph. X (income) No. of persons Cumulative frequency (cf) 180 16 16 200 24 40 250 26 66 280 30 96...
1 answer
Review The 15-kg block is held at rest on the smooth inclined plane by the stop...
Review The 15-kg block is held at rest on the smooth inclined plane by the stop block at A. (Figure 1) Part A If the 10-g bullet is traveling at 300 m/s when it becomes embedded in the 15-kg block, determine the distance the block will slide up along the plane before momentarily stopping. Express yo...
1 answer
4 m /s - 0.5 m- 0.5 m- 7-73. The Rankine body is defined by the...
4 m /s - 0.5 m- 0.5 m- 7-73. The Rankine body is defined by the source and sink, each having a strength of 0.2 m2/s. If the velocity of the uniform flow is 4 m/s, determine the longest and shortest dimensions of the body....
1 answer
Can you please explain how they got the answer for each question, I dont understand how...
Can you please explain how they got the answer for each question, I dont understand how to do them. Please explain it in great depth since I am a beiginner in Organic Chemistry. 77. Predict the product(s) for the following reaction. H3 H3 H3C H3C A) I B) II C) III D) IV E) none of these Ans: B 84. ...
1 answer
The fiscal year ends December 31 for Lake Hamilton Development. To provide funding for its Moonlight...
The fiscal year ends December 31 for Lake Hamilton Development. To provide funding for its Moonlight Bay project, LHD issued 7% bonds with a face amount of $630,000 on November 1, 2021. The bonds sold for $567,653, a price to yield the market rate of 8%. The bonds mature October 31, 2041 (20 years)....
1 answer
QUESTION 2 0.5 A vessel contains a mixture of 27.8 grams of H2 (g) and 16.0...
QUESTION 2 0.5 A vessel contains a mixture of 27.8 grams of H2 (g) and 16.0 grams of CH4. If the total pressure inside the vessel is measured at 3.21 atm, the partial pressure of H2(g) must be atm. O C 6.03 0.217 O O O O QUESTION 3 0.5 p Zinc reacts with aqueous sulfuric acid to form hydrogen gas: Z...
1 answer
How do you solve #\frac { ( b + 1) } { 2} = \frac { ( b - 2) } { 5}#?
How do you solve #\frac { ( b + 1) } { 2} = \frac { ( b - 2) } { 5}#?...
1 answer
Explain how nonhomologous morphological characters can reveal “deep homology,” and how deep homology can be considered...
Explain how nonhomologous morphological characters can reveal “deep homology,” and how deep homology can be considered a special case of homology and mapped as such onto a phylogenetic tree, as done by McCune and Shimenti. Please explain in depth...
1 answer
I really need help understanding/interperting this graph. the question is : how much of mortatality rate for CVD can be...
I really need help understanding/interperting this graph. the question is : how much of mortatality rate for CVD can be reduced if people are most fit in CRF compared fo one with least fit? (answer for both men and women) Men 1.01 P for trend <0.001 in men and <0.001 in women Women 0.8 0.6 ...
1 answer
A river penetrates a confined gravel aquifer of 2 m thickness and receives flow from the...
A river penetrates a confined gravel aquifer of 2 m thickness and receives flow from the aquifer on both banks. From both sides, the hydraulic gradient towards the river is 5 m/km. Over a linear section of the river between gauging stations 4 km apart, the river flow rate increases by 1000 litres pe...
1 answer
If #F(x)=int_1^(x^2)sqrt(t^2+3)dt#, then #F'(2)=#?
I anti-differentiated this function and plugged the value in, I got #sqrt(19)^3*8/3-16/3#. However, the correct answer is #4sqrt(19)#. Is my answer wrong or I need to simplify it? If so, how? Thank you!...
1 answer
A model rocket has a horizontal range of 260 m on level ground, when given a...
A model rocket has a horizontal range of 260 m on level ground, when given a 45 degrees launch angle. What horizontal distance will the rocket cover when launched at 45 degrees to the horizontal from the top of a hill whose sides slope down at 25 degrees?...
1 answer
5, D33. Geographic separation is an important factor in 03 speciation. allopatric parapatric anagenesis sympatric
5, D33. Geographic separation is an important factor in 03 speciation. allopatric parapatric anagenesis sympatric...
1 answer
What causes radioactivity?
What causes radioactivity?...
1 answer
1,Mar 28th, 70 questions, 120 minutes ted: Mar 10 at 5:08pm siz Instructions Joints maximum Question...
1,Mar 28th, 70 questions, 120 minutes ted: Mar 10 at 5:08pm siz Instructions Joints maximum Question 16 A culture medium contains water, glucose and 6 types of salts. What is this type of medium classified as? Defined medium Complex medium Selective medium Differential medium • Previous No new ...
1 answer
Equivalent units of production Equivalent Units of Production The Converting Department of Hopkinsville Company had 840...
equivalent units of production Equivalent Units of Production The Converting Department of Hopkinsville Company had 840 units in work in process at the beginning of the period, which were 75% complete. During the period, 17,600 units were completed and transferred to the Packing Department. Ther...
1 answer
Accounts payable refer to obligations owed (by/to) the business and are classified as a(n) (asset/liability/expense) account.
Accounts payable refer to obligations owed (by/to) the business and are classified as a(n) (asset/liability/expense) account....