• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Help, suggestions needed  RSS feed

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a shopping cart. I have list of books, each book has a link "Add to Cart", which adds books to a vector. When clicked on some other book it is also added to vector. I display all these books along with price and Author by enumerating through the vector.
Problem: I want to display the Grand total(price of book1 + price of book2) of books, how can i do that?
Part of code which displays elements of class shoppingcartElement is:
Enumeration en =vec.elements();
while(en.hasMoreElements())
{
shoppingcartElement shopelement1 = (shoppingcartElement)en.nextElement();
//GrandTotal=shopelement1.total(previous instance)+(newinstance);
}
My shoppingcartElement class:
import java.lang.*;
import java.util.*;
public class shoppingcartElement extends Object{

public String bookname;
public double price ;
public int quantity;
public int sku;
public double total;
}
thanks for the help in advance.
arpit
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about using..
GrandTotal = 0;
loop {
GrandTotal = GrandTotal+currentItem.price
}
?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!