user249375
user249375

Reputation:

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..

Upvotes: 1

Views: 144

Answers (2)

Binary Nerd
Binary Nerd

Reputation: 13927

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

Upvotes: 0

Uri
Uri

Reputation: 89729

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

Upvotes: 3

Related Questions