public void addItem(CartItem item) throws Exception { if(item == null) { //...(throw an exception) } if(item.getBookOrCD().equals("B")) { // if the item is a book boolean found = false; for(int index=0; index < BookList.size(); index++) { CartItem temp = (CartItem)BookList.elementAt(index); if( //... (if the item to be added is the same as the temp item) { found = true; // the cart has another copy of the same item // ...(set the quantity for temp to quantity + 1) // ...(store the updated item in the vector) // ...(update the total price by adding the unit price of // current item multiplied by the quantity of such items // you are adding in the cart right now) break; } } if(!found){ // if the cart did not have another copy of the same item // ...(add the item to the vector which is a list of books) // ...(update the total price of all items in the cart) } } else { // if the item is a CD //...(similar implementation for the case of a CD) //... //... //... //... //... //... } }