having problem adding to a collection

I am adding information about different books, cd, dvd from main() I am trying to use inheritance in this project...

First, i am a beginner so keep that in mind when you help me. please try to keep it really simple.. I will post partial code where i need help then i will post the full code at the bottom..

now in the items class

i am not sure what i do with the item being passed in?

class CD extends Item { private String artist; private String members; private int number; public CD(Item musicCD, String... members) // need help { members = members; }

please keep in mind i am new to java. Thank you..

-------------Problems Reply------------

This is probably a homework question, but I think you are starting way too big before understanding a lot of the smaller concepts. If this is from a book, you may want to do some simpler exercises first. There are too many concepts you are likely not familiar with that are involved in building this system.

From a quick glance, here are several issues:

1) I didn't see where you were initializing your sets. Right now, they will be null - you just declared them. You would probably want a hashset or a treeset.

2) Your various classes don't support equals or hash codes, you will see problems when you insert and try to retrieve them.

3) Add band members should not create a new CD - you are already passing in a CD, or at least an ID that you can use to look up a CD in your set.

4) Your constructor of CD is messed up. E.g., why are you getting a CD item as the first parameter? In addition, you might not be setting the members right. Try something like this.members = members

Since your using HashSets you will need to override the equals and hashcode methods as @Uri has pointed out. Here's a good article with examples for doing this. Its worth a read so you know exactly what your doing.

Equals and Hash Code in Java

Category:java Views:0 Time:2010-02-16
Tags: java

Related post

  • ASP.NET - new user control added to control collection get unexpectedly a value 2009-07-25

    I have created user control container (panel actually) which dynamically adding and removing user controls items (like rows). Here is the problem: when the new user control is added to control collection get unexpectedly a value from the previous add

  • the value of type "-" cannot be added to a collection or dictionary of type 'uielementcollection' 2011-04-28

    I am gettig following error when i am adding a custom control thru XAML. what can be the possible reason? the value of type "..." cannot be added to a collection or dictionary of type 'uielementcollection' <Grid x:Name="QuantityDetail" DataContext

  • Issue Adding to Observable Collection 2012-01-27

    I have a problem adding items to an Observable collection, I've tried a few things over the last few hours and still not making it threw debugging. The error is Object reference not set to an instance of an object. here is the code. public class IPer

  • Downloaded Podcasts always added to my collection 2014-11-12

    I think about two updates ago, podcasts I have downloaded started to be marked automatically as "Add to collection" and show up as "In Collection" instead of just "Automatic." I rarely if every download a podcast and save it. But now matter how many

  • Problem adding new content! 2014-12-26

    I have never had a problem adding content to my Zune but all of a sudden it is not finding my new video folder. I have a 120 GB Zune. --------------Solutions------------- Hello, Is the Zune Software "finding" the "new video folder"? If NOT than ->

  • Problem adding lots of strings to a TStringList 2009-12-14

    I have a problem adding strings to a TStringList. I've searched other posts but couldn't find an answer to this. What I'm trying to do is to add a big amount of strings to a TStringList (more than 14000) but somewhere in the process I get an EAccessV

  • adding to a collections - inheritance 2010-02-16

    I am trying to make a project that adds cd / dvd /movie info from main() to a collections library then prints info added. like: output -Book- author: Robert A. Heinlein # pages: 325 title: Starship Troopers keywords: science fiction, war, weapons -Mu

  • Problems adding git remote repository 2011-02-18

    I'm having problems adding a remote repository to my local one. I first tried using Tower where I manged to add my local repo, but when it came to adding a remote repo it just said add the URL. It doesn't say anything about this URL. Should it includ

  • 'ConstrainExtentBehavior' cannot be added to a collection or dictionary of type 'BehaviorCollection' 2011-07-22

    i am currently doing a silverlight c# application , following a sample code in the arcgis website, i added this code in the xaml page to add the constrainextent function. there is no other code in the xaml.cs page. <i:Interaction.Behaviors>

  • Problem adding object to NSMutableArray 2011-08-26

    I am having problems adding objects to my NSMutableArray. It seems that something gets added (object count increases by 1 in debugger), but the only thing added is a 0x0 (null) instead of the address of an object. I've read through everything somewha

  • Backbone.js Adding Model to Collection Issue 2011-12-13

    I am building a test application in Backbone.js (my first app using Backbone). The app goes like this: Load Data from server "Plans" Build list of plans and show to screen There is a button to add a new plan Once new plan is added, add to collection

  • Having problems adding markers into Google Maps clusterer 2012-02-08

    I have problem adding markers into marker Clusterer of Google Maps. Firebug returns error: Error: Invalid value for property : [object Object]' when calling method: [nsIDOMEventListener::handleEvent] Markers are created with mix of JavaScript and PHP

  • Having problems adding Microsoft Office 2010 "trial" version. I will need to save it to my desktop. 2013-05-04

    I'm having problems adding a Microsoft Office 2010 "trial" version. I will need to save it to my desktop. Using an older hp pavilion mx 50 computer with Windows XP; while at work with a Law Firm. I usually save work on a CD and print work at home on

  • Problem adding Windows 7 laptop to home network with XP desktops 2012-08-02

    I'm having problems adding a new Windows 7 laptop to an existing wired/wireless home network, which has three XP desktops. The laptop connects to the internet fine. The desktop shows the laptop icon. The laptop shows the desktop icon. But neither wil

  • Why am I getting new music added to my collection? I am not paying for them. 2012-12-13

    I installed Zune on my computer a week ago because I was given a Windows phone and I needed Zune to add music. I didn't really know what to do with it so I was going to figure it out later. And now, when I opened it up again, a bunch of music was add

  • There's a problem adding your account right now. Please try again later 2012-12-16

    I'm trying to get my Outlook Express email into the cloud before changing my Windows XP laptop to a new Windows 8 model. I signed up for a new live mail account (@outlook.com.au) and it offers to import my emails using the Mail Migration app. I insta

  • Problems adding a search provider in I.E.9/64-bit, says "not available" 2012-12-25

    I have a Toshiba laptop with Windows 7 Home Premium, 64-bit. I am using I.E. 9 (64 bit) as my default internet browser. Bing is my default search provider. I am trying to add Google as my second search engine. However, when I go to: Tools/Manage Add-

  • I am unable to add this account on my Verizon Droid X. No problem adding the old hotmail account. 2013-10-05

    I am unable to add this new Outlook.com account on my Verizon Droid X. No problem adding the old hotmail account. --------------Solutions------------- On your phone, features that use the new @Outlook.com address will stop working, including Marketpl

  • Zune Pass adding Albums to collection. 2014-01-27

    I have a zune pass, I want to download the Album The Brit Awards with mastercard 2012 (various Artists). The first two songs say Album Only and do not get added to my collection when i download the album. Why is this? That is the album starts to play

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.073 (s). 11 q(s)