This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!

Cruz Loyde

Greenhorn
+ Follow
since Nov 03, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cruz Loyde

Carey Brown wrote:A personal preference:
I can see throwing an exception if null is passed in, however, I'd rather have a boolean returned as to whether the add was successful or not.


Prof gave sets of instructions on how to do the methods so i really cant do my own thing.
2 weeks ago

Piet Souris wrote:As an aside: the singular form of media is medium (well, in Holland anyway). But admitted: many people talk about 'medias' as plural.

@OP
are you being taught about the 'equals' method? Campbell and Liutauras mentioned it, but it would simplify your code.


I was only taught to use .equals like that
2 weeks ago

Liutauras Vilda wrote:https://www.ilikeyouroldstuff.com/news/11-songs-that-are-also-movie-titles


2 weeks ago

Knute Snortum wrote:What happens when currMedia and Media have the same title but not the same category?  Is that the behavior you want?


I think so because the object sets up like this
Correct me if im wrong.
2 weeks ago

Norm Radder wrote:Are you sure with that code?  It only allows 1 of any category.
Should the test compare BOTH the title AND the category to determine a match?



Oh yeah thank you for pointing that out. Is ths better and/or correct one?

2 weeks ago

Norm Radder wrote:The logic would be like this:
Check if item is in list
If item is not in list, add item

No remove, no counting duplicates.



I FIGURED IT OUT, I WAS SO HAPPY LOL!!
2 weeks ago

Norm Radder wrote:Did you see my earlier post?


If the object is to NOT add a duplicate, what is the purpose of the duplicate variable and remove method?

If the list contains an item that is the same as the one to be added, why not just exit the method when the match is found and NOT add the new item?



Welp Idk anymore, i give up, GG

Thanks for the help anyway.
2 weeks ago

Norm Radder wrote:

im trying to prevent the duplicate from adding


Can you post the code for the method that prevents adding a duplicate?



2 weeks ago

Norm Radder wrote:

line 36 is failing


I see line 36 to be:  @Test
How does that line fail?

Is there an error message?



Starting from 36 to 50, thats for testing if duplicate is prevented from adding. What im getting is that i have 3 objects in my list instead of 2 even tho im trying to prevent the duplicate from adding
2 weeks ago

Norm Radder wrote:

The 3rd test is failing.


What line(s) is the 3rd test?

How can anyone compile and execute the code for testing?  Missing imports and class definitions



import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

import edu.westga.cs1301.media_library.model.Media;
import edu.westga.cs1301.media_library.model.MediaLibrary;

line 36 is failing
2 weeks ago

I think to add an object to the list. The 3rd test is failing.
2 weeks ago

Norm Radder wrote:Did you look at the API doc for the ArrayList class to see if any of its methods would be useful?
http://docs.oracle.com/javase/8/docs/api/index.html





This is my new code, still struggling why it would not pass my tests.
2 weeks ago

Norm Radder wrote:What class is the container that holds the items?  Many classes have methods to detect if they hold an item.



2 weeks ago

Norm Radder wrote:

use it aswell to remove the duplicate.


Removing duplicates is different from preventing duplicates.
Which is the goal?



Prevent, sorry about that.
2 weeks ago

Campbell Ritchie wrote:Welcome to the Ranch

Please explain what that code is supposed to do, and whether there is supposed to be any relationship to the thre‍ad title. I can see nothing in there that would prevent duplication. Please remove the loop, because it doesn't do anything. What you are doing is iterating something, then testing whether its title equals itself, then getting a title and not doing anything with it. So the loop takes time to achieve nothing.
Then you are adding the object to the Iterable, unless it is null.

Don't have a field and a parameter with the same name; that is a good source of confusion. It is maybe better to throw a null pointer exception f you are presented with a null, or better still condense the method toThat will throw the exception for you if you pass null. But I can't say more until I know what you mean about duplicates.



What i planned is that to use the for loop to go over my list and remove the duplicates. I refered my code to this. Since its trying to find the longest i thought i could use it aswell to remove the duplicate.
2 weeks ago