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 6570137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:43:06+00:00 2026-05-25T14:43:06+00:00

Hello again fellow programmers. so I’m creating a program that allows users to specify

  • 0

Hello again fellow programmers.

so I’m creating a program that allows users to specify the type of insurance cover they want as part of an insurance policy.

Since their is only 4 types of cover to choose from I want to use a set or hash set to keep track of the types of cover offered to users.

The problem is that is does not seem to get rid of duplicates it is treating it like an arraylist and when I print out the contents of the set i get duplicates which should not happen in a set.

This is the code I used to pass the created insurance type objects to the insurance policy class.After they have been instantiated.

CoverType theInsuranceType = new CoverType("Fire",250);
theInsurancePolicy.includeCover(theInsuranceType);

and this is the code I used in the insurance policy class to keep track of the type of insurance that a user has taken out.

    import java.util.*;
    // Class:   InsurancePolicy
    // Purpose: To represent a particular customer's insurance agreement
    public class InsurancePolicy {


            //ArrayList<Product> orderList = new ArrayList<Product>();
        private static int totalPolicyCost;

        private static String name = null;

        private static int price = 0;

        private int amount = 0;

        private static int total = 0, claims = 0;


        private static Set<CoverType> TheCoverType = new HashSet<CoverType>();


        public static boolean includeCover(CoverType which)
        {

            TheCoverType.add(which);
            System.out.println(which.getName()+" Has ben added to your insurance    policy");
            System.out.println(" ");
            System.out.println(" ");
            System.out.println("-----------------------");  
            return true;

        }

I have done this as part of the the insurance policy class to iterate over the set and pull out and print values of each object for the user and that is where im getting the duplicates.

    Iterator<CoverType> iter = TheCoverType.iterator();
        int cash =0;
        while (iter.hasNext())
        {
            CoverType type = iter.next();
             cash =  type.getPrice();
            amount = amount + cash;
            System.out.println("This one Cost.  "+ cash);
                        // int cost = TheCoverType.getPrice().next();
//          if theCover     


        }
        amount = amount+ 100;
        String message = "So all up total cost of the policy is. "+cash; 
        return amount;

Any help will be greatly appreciated.

  • 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-25T14:43:07+00:00Added an answer on May 25, 2026 at 2:43 pm

    The type held by the set I assume is “CoverType”, right? If so, do you overload equals and hashCode() for this class?

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

Sidebar

Related Questions

Hello Again my fellow programmers out there, I'm designing and programming from scratch a
Hello I've runned in to a problem again that I can't solve on my
Hello fellow StackOverflow users (or Stackoverflowers ?): I'm learning-by-coding WPF. I read several articles/saw
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hello can anybody solve this please I'm creating the object in the action class
Hello I am compiling a program with make but I get the error of
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello again stackoverflow... Once again I have a troublesome problem. I have a page
Hello again great knowledge masters of stackoverflow, once again the small coder apprentice tabaluga

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.