CodeGym /Courses /Java Multithreading /Practice using anonymous inner classes

Practice using anonymous inner classes

Java Multithreading
Level 4 , Lesson 9
Available

"And here are new tasks for my friend:"

13
Task
Java Multithreading, level 4, lesson 9
Locked
Refactoring, anonymous classes
Be sure that the getIterator method returns an anonymous class. Transfer the LocalIterator logic to an anonymous class. Only change the body of the getIterator method.
7
Task
Java Multithreading, level 4, lesson 9
Locked
Let's recall inheritance
Fix inheritance in all the classes so that the output of the main method is "CCBAYS".
26
Task
Java Multithreading, level 4, lesson 9
Locked
Knowledge is power!
1. In the sort method, write a comparator for Stock: 1.1. Sort first by name in alphabetical order 1.2. Sort second by date without accounting for hours, minutes, and seconds (with the newest on top), and then by profit from positive to negative ... open 125.64 and last 126.74. Here the gain is 126
Comments (12)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Lisa L Level 47, Nuremberg, Germany
6 May 2022
Knowledge is power: If you use Comparator.comparing() you just need getters in the Stock class for name and date and a method that calcs the profit (if key 'change' is in the map -> change, else 'last' - 'open' ... thanks Dan). then you just chain together the Comparators and you're done (use method references as parameter for the comparing(), then comparing methods like Stock::getName, that way you save a lot of anonymous class overhead) the chain then looks smth like that: Comparator.comparing(... the method ref ...).thenComparing(...).... Don't forget to reverse the last property. For that there is a overloaded thenComparing method that takes a second argument (keyExtractor and keyComparator -> the keyExtractor is the above mentioned method reference for the keyComparator you can use one of Comparators static methods: reverseOrder()). The result then looks stunningly simple.
Dan Level 26, Clarksville, United States Expert
17 December 2021
The final challenge was incredibly difficult for me. Without spoiling anything, here's my advice. Once you've created your comparator and fixed the exception issue: 1: Make sure the the stocks sort alphabetically 2: Make all stock names the same, and ensure that the list populates first with the newest stock Date (Jan 2 2032 should appear before Jan 1 2032) 3: Make all stock names AND dates the same, and ensure that the list populates with the highest profit per day (Change 0.06 is bigger than open 1.00, last 1.05) Info on calculating profits: Stocks with change -- They give you the end of day totals, and they tell you whether it was a positive or negative change Stocks with open and last -- You have to do the legwork here to figure out if the stock went up or down. If it opens at 2 dollars and ends at 1.99, that means the profit is -0.01 Good Luck!
Andrei Level 41
13 April 2021
Bro... Knowledge is power... bro.. no, bro.. just no... that's another programming language...wth...
MaGaby2280 Level 41, Guatemala City, Guatemala
7 August 2020
These tasks make no sense to me... and harly help in understanding anonymous classes...
MaGaby2280 Level 41, Guatemala City, Guatemala
7 August 2020
* hardly, not harly
BlueJavaBanana Level 37
7 August 2020
Yeah, get ready for more confusing stuff! I'm doing my best to try understand things not just copy and pasting, I don't understand why they need to introduce so many new things in some tasks, makes overall learning impossible.
Andrei Level 41
9 April 2021
I just hope it's one of those ways of thinking, we make it hard as hell now, so later when you are working it will be easy peasy.. you know, like Navy SEAL training, a period of hell and then you're a top soldier.. At least this is what I hope! That everything has its purpose here.. hopefully... 🤣 P.S. and then get to senior developer in 1 year thanks to all of the knowledge gained here 😆
matemate123 Level 50, Kraków, Poland
13 April 2023
And now after two years from this comment, what you can say about it? This method learning worked for you?
Andrei Level 41
17 April 2023
I wouldn't say it was that efficient. It was good, but no the best. I would approach it differently.
matemate123 Level 50, Kraków, Poland
17 April 2023
I have similar insights, It's great for guys whose have predisposition to thinking in that fields. For normal people can be hard and disapointing. Do you have some tips from your succes position? :D
Andrei Level 41
21 April 2023
If it's hard for you to motivate yourself, continue with CodeGym. If you can easily motivate yourself, first learn Java basics, maybe read the book for the OCA exam. Then learn Spring Boot, Maven (udemy courses), learn about REST and API's, start buildling Java backend projects (testing with postman for front end) -see Bezkoder, AmigosCode- using microservices style, check job descriptions for JR java and see what else is required and learn that. But for tech interviews you really need to know the basics (OCA book or OCP book) and then have a portfolio on which to discuss you knowledge.
matemate123 Level 50, Kraków, Poland
21 April 2023
Thanks for good sources!