Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sum  RSS feed

 
Naveen R R
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could anyone help me with this? I am trying to sum the no. of estimated hours for all project phases and display it on the jsp page.
Example:
Phase Est.Hours
------------------
Initiation 5
Analysis 10
Design 15
---------------
Total 30
The phases and hours are retrieved from the database.
But, I am unable to sum it up with the below given code. I think one problem is totEstHours & estHours are strings.

<TD align="center" valign="bottom"><B>Total Hours</B></TD>
<%
beans.project.DataTable prjPhase = projBean.getProjPhase();
String totEstHours = "";
for (int r = 0; r < prjPhase.getRowCount(); r++) {
beans.project.ProjectPhaseBean pBean =
(beans.project.ProjectPhaseBean)prjPhase.getRow(r);
%>
<%
String estHours = "";
if (pBean.getEstimatedHours() != -1) {
estHours = new Integer(pBean.getEstimatedHours()).toString();
}
totEstHours += estHours;
%>
<TD align="center" valign="bottom"><%=totEstHours%></TD>
<% } %>
Thanks,
Naveen
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use ParseInt() to convert the strings to ints.

Bosun
 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Declare total estimated hours as int instead of String.
If pBean.getEstimatedHours() returns int, just add 'em up or use ParseInt if it is a string.
(ie. I don't see a need to create Integer objects).

------------------
_________________________
Rama Raghavan
SCJP2
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!