title: How to calculate grand total servlet
body: <p>Hi in my servlet I've got for loop to display content of cart, I want add to it "grand total" for all items in cart to calculate total for item I have</p>
  
  <pre><code>public double getTotalCost() {
          return (getItemCount() * getItemPrice());
  }
  </code></pre>
  
  <p>my for loop looks like </p>
  
  <pre><code>for (SimpleItem item : previousItems) {
  out.println("&lt;TR&gt;"
  + "&lt;TD&gt;"+ item.getItemName() + "&lt;/TD&gt;"
  + "&lt;TD&gt;"+ item.getItemArtistDirector() + "&lt;/TD&gt;"
  + "&lt;TD&gt;"+ formatter.format(item.getItemPrice()) + "&lt;/TD&gt;"
  + "&lt;TD&gt;&lt;DIV&gt;"+ "&lt;FORM id ='2' ACTION='OrderPage'&gt;" 
  + "&lt;INPUT TYPE='HIDDEN' NAME='title' VALUE='" + item.getItemName()+ "'&gt;"
  + "&lt;INPUT TYPE='HIDDEN' NAME='artistDirector' VALUE='" + item.getItemArtistDirector()+ "'&gt;"
  + "&lt;INPUT TYPE='HIDDEN' NAME='price' VALUE='" + item.getItemPrice()+ "'&gt;"
  + "&lt;INPUT TYPE='TEXT' NAME='numItems' SIZE=3 VALUE='" + item.getItemCount() + "'&gt;" + "&lt;SMALL&gt;"
  + "&lt;button TYPE='SUBMIT' formaction = 'OrderPage'&gt;Update Order&lt;/button&gt;" + "&lt;/SMALL&gt;"
  + "&lt;/FORM&gt;" + "&lt;/DIV&gt;&lt;/TD&gt;"
  + " &lt;TD&gt;"+ formatter.format(item.getTotalCost())+"&lt;/TD&gt;"
  + "&lt;TD&gt;"+ item.getTotal() + "&lt;/TD&gt;"
  );
  }
  </code></pre>
  
  <p>My question is how my method for grand total must looks like I have tried </p>
  
  <pre><code>   public double getTotal(){
          Double temp = getTotalCost();
          if(getTotalCost()!=temp){
            temp = temp + getTotalCost();
          }
          return(temp);
      }
  </code></pre>