CodeGym /Java Course /Java Collections /Big task: AbstractList class

Big task: AbstractList class

Java Collections
Level 1 , Lesson 15
Available

"Hello, soldier!"

"Congratulations on upgrading your skills. We need guys who are prepared to do anything."

"I'm sure you still have many unfinished tasks. It's time to finish some of them!"

14
Task
Java Collections, level 1, lesson 15
Locked
Build a tree (part 1)
Amigo, it seems you may now have an adequate foundation. It's time to test your skills by doing a big task! Today, we'll implement our own tree in a slightly non-standard way (based on AbstractList). To get background information, use your favorite search engine and the text below.
14
Task
Java Collections, level 1, lesson 15
Locked
Build a tree (part 2)
Despite the fact that our tree descends from the AbstractList class, it is not a list in the traditional sense. In particular, we don't have access to methods that take an element's index as an argument. You need to override such methods and throw a new type of exception: UnsupportedOperationExcept
14
Task
Java Collections, level 1, lesson 15
Locked
Build a tree (part 3)
We've created a class that defines a tree. Now we need a class that defines the nodes of a tree: 1) In the CustomTree class, create a static inner generic class Entry<T> with the default access modifier. 2) Make this class support the Serializable interface.
28
Task
Java Collections, level 1, lesson 15
Locked
Build a tree (part 4)
Every tree starts with a root, so don't forget to add an Entry<String> field called root with the default access modifier to the CustomTree class. Initialize it in the CustomTree constructor. It's name (elementName) isn't important.
28
Task
Java Collections, level 1, lesson 15
Locked
Build a tree (part 5)
We can add elements to the tree. Now let's work on deleting them: Implement the remove(Object o) method, which will remove the tree node whose name was passed as an argument. The method must throw an UnsupportedOperationException if the argument is not a String.
Comments (18)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
cute potato Level 46, Poland, Poland
4 February 2023
Like without explanation about the tree data structure you give such hard tasks? Gosh...
Justin Smith Level 41, Greenfield, USA, United States
17 August 2022
This was hard, but really cool. Step 4 is by far the hardest leap in logic, but once you have gotten there, Step 5 is just a continuation of that logic and not terribly hard in itself.
Lisa Level 41
11 December 2021
I just read a book about data structures and a huge part of it was about trees (needed 5 or 6 weeks for that). Without that knowledge I'm 100% sure that I never would have been able to solve this task.
matemate123 Level 50, Kraków, Poland
24 August 2023
Can you tell us what title this book has?
Jurij Thmsn Level 29, Flensburg, Germany
24 May 2021
Nice tasks! Hard, but doable without having to google any new classes etc. Just used ArrayLists, Queues and a lot of if-statements. And a commented "right solution" - finally! (even though I don't really understand it 😬)
MaGaby2280 Level 41, Guatemala City, Guatemala
19 May 2021
Wow! These task really hurt my brain... there should be a better explanation for part 4 and 5!
joe Level 27, London, United Kingdom
19 January 2021
Really need some explanation for parts 4 and 5. Like BlueJavaBanana said there's a ridiculous difficulty jump from parts 1 to 3. "do a little work on your own" I laughed .........
LennyMan Level 25, Lucca, Italy
13 January 2021
Someone can please explain what happen here: private transient ArrayList<Entry<String>> queue; Is it in the solution of the part4
BlueJavaBanana Level 37
3 January 2021
Dreadful task. Part 1,2,3 are a joke easy. Then boom make the tree logic with zero clues as to how they might want you to solve it. Got a working solution? Well too bad the validator don't wanna know!
Romain Level 26, Paris, France
15 March 2021
I thought it too, but when you understant you just need to add a list in your customTree class, it becme easy. ^^
allthemore Level 41
4 August 2020
Questions to part#5: What is the logic that we add node#16 to the node#9 and not any other node? I don't understand this algorithm. And if we want to add node#7 once again after we removed node#3, which parent node will be a new parent for node#7?
5 June 2020
One helpful clue is to use: Queue<Entry<String>> nodes = new LinkedList<>(Collections.singletonList(root));