Building a bag class in Java
I’m in https://www.londonbc.co.uk dire need of help with this project. I’m trying to implement a Bag class for a programming assignment, and I’m getting hung up canada goose outlet on the addAll(), Union(), and equals(), methods.
Edit: According to the assignment, addAll() is supposed to add all of Canada Goose Outlet the the objects from the second array into the first. I’m no longer getting an error when I run it, but for some reason it will not add all of the elements from the second array, it will only add the first 2. Thanks guys, this cheap canada goose one is working perfectly now!
Edit: For Union(), I’m supposed to create a third bag that will contain canada goose outlet store uk all the contents of the first 2 bags. I was getting an ArrayIndexOutOfBoundsException when running this method. Thanks again!
Edit: « First attempt » And for equals(), it’s supposed to check the size of the bags to make sure they are equal canada goose outlet sale in size, cheap canada goose then check to see if they contain the same numbers. So as it’s written now, my equals() method will compare sizes and return the boolean value for that, but I’m unsure of how to make it compare the actual values.
EDIT: canada goose factory outlet Thanks to everyone for your help, you guys are canada goose uk black friday life savers.
I think you have a lot of problems with the design of canada goose coats on sale the class that you should address first. If you are representing the bag canada goose outlet uk sale as a static or dynamic array then you only need one array, not 2. You also don’t need two bags inside each bag as attributes, that doesn’t make any sense; all you canada goose clearance sale should canada goose outlet toronto factory have left is the size of the bag or count and the array to hold all the elements (which are integers in your case). Also, avoid naming parameters for functions and attributes for the class the same way.
If you make these changes, the rest should be straight forward from here. Since canada goose outlet online uk it’s Canada Goose Coats On Sale canada goose jacket outlet an assignment, you should make these changes and try again because you won’t learn if we provide the answers for you; you’ll see Canada Goose Jackets it will be much easier once you structure it correctly. it’s a convention to start a class name with a capital letter. The function is canada goose black friday sale intended to add elements from one bag in to another bag, so why does the caller have to specify three different bags? There’s only two involved.
Second problem is that the function isn’t implemented correctly, but I think that’s because you’re getting confused because canada goose store you’ve got three bags involved instead of two. To sketch out how it should be fixed:
Bag target =.
Bag source =.
for canada goose outlet black canada goose black friday sale friday (int i = 0; i
Good variable naming is your friend.
You haven’t specified what problem you’re having with your implementation, so I’m not going to simply official canada goose outlet rewrite it for you. Edit your question with the problem, and I’ll help.