Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5946301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:48:13+00:00 2026-05-22T16:48:13+00:00

I have a ShoppingCart app that can add/remove Book objects A book has an

  • 0

I have a ShoppingCart app that can add/remove Book objects
A book has an isbn attribute.
I need to check if someone has added a duplicate copy of same book to the cart
ie,

Book b1 = new Book("isbn222");
Book b2 = new Book("isbn222");
Book b3 = new Book("isbn333");
Book b4 = new Book("isbn444");
Book b5 = new Book("isbn444");
Book b6 = new Book("isbn444");
Book b7 = new Book("isbn555");
//add these to cart

In this case I want to generate a warning to the user that duplicates 2 copies with isbn222, three copies with isbn444 are added.
I thought of creating a CartValidator as below,However,I couldn’t implement the logic given below..How do you create sub lists in java?
Any help regarding this much appreciated.

thanks

mark.

public class CartValidator {
    public static String validate(ShoppingCart<Book> cart) {
        StringBuffer warning = new StringBuffer("duplicates");
        List<Book> items = cart.getItems();

        /*
         * take first item from list,       temp= items.get(0)
         * check against all the rest for duplicates and build warning  compare with item1,item2..
         * take second item                 temp= items.get(1)
         * check against all the rest for duplicates and build warning   compare with item2,item3..
         */

        return warning.toString();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:48:14+00:00Added an answer on May 22, 2026 at 4:48 pm

    I would suggest to have Map with <String, List<Book>>. where String key the Book ISBN and the list is the books with the ISBN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app (rails 3.1.3) that has a shopping cart model. I
I have 2 pages I created in ASP.net(C#). The first one(called shoppingcart.asp) has a
I have a shopping cart in my app and an underlying data structure that
I have a page that consists of two frames: one being a flash app,
Or vice versa. Update: Hmm, let's assume I have a shopping cart app, the
I'm making a shopping cart app in Google App Engine. I have many classes
I have a .net website written in C# and will make functionalities that other
I have 2 tables, ShoppingCart which holds items in basket and Sales which records
I have three classes; Stamp, Letter and Parcel that implement an interface IProduct and
I have shopping cart web application. when I am running that in my local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.