CodeGym /Java Course /Java Core /Tasks | Level 5 | Lesson 2

Tasks | Level 5 | Lesson 2

Java Core
Level 5 , Lesson 2
Available

"Yesterday, robbers broke into my house, turned everything upside down, and sifted through the whole house, looking for money."

"That's horrible, Diego. What did you do?"

"Nothing. I started laughing with them and joined them in the search for money. Ha-ha."

"Since my house is a total mess, I couldn't find your task. I'll have to wing it. Here you go."

4
Task
Java Core, level 5, lesson 2
Locked
OOP: Arrange interfaces
Clothing can (and should, perhaps) be worn, sold, and bought, preferably at a discount. Let's tell the world. We'll add the Movable, Sellable, and Discountable interfaces to the Clothes class, if possible. And then we'll implement their methods (big surprise!).
4
Task
Java Core, level 5, lesson 2
Locked
OOP: Animal inheritance
Next to a mouse, even a goose is enormous. But next to a dragon... In this task, we have geese (Goose class) and dragons (Dragon class). As well as their ancestors, BigAnimal and SmallAnimal classes. Guess for yourself whose ancestor is whose. Then override the String getSize() method for Goose and Dragon so that they display strings about the animal's size.
8
Task
Java Core, level 5, lesson 2
Locked
OOP: Cars
Let's categorize cars. Create classes for affordable and expensive cars, and then make the Ferrari and GeoMetro classes inherit them as you see fit (but please note that the CodeGym code validator has a definite opinion on the matter). We'll implement printlnDesire methods in these classes that will tell us the secret desires of their drivers.
16
Task
Java Core, level 5, lesson 2
Locked
OOP: Books
In this task, we will create books written by the earthly authors Mark Twain and Agatha Christie. Using the MarkTwainBook and AgathaChristieBook classes, naturally, which inherit Book. You need to implement all the abstract methods in these classes. And in the parent class, implement the getOutputByBookType method.
8
Task
Java Core, level 5, lesson 2
Locked
OOP: Fix inheritance problems
Let's investigate some body parts. First, we'll check whether bones are present. You need to fix the containsBones method and all associated logic so that, without changing the program's behavior, it returns an Object: "Yes" instead of true, and "No" instead of false.
Comments (46)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Ryan D Vibbert Level 26, United States of America, UK
3 January 2023
The books task should be allowed to be done with creating new files. I had done that since that is best practice and the verifier didn't allow it for obvious reasons. We should consider allowing it with separate files for good practice with inheritance.
Riccardo Level 33, Italy
28 November 2022
Hello, Could you explain to me why in the OOP: Books task the System.out.println(books) method returns the value of getOutputByBookType() if this is not called? thank you
Anonymous #10978528 Level 30, Immelborn, Germany
8 January 2023
it is indeed called in the toString() method.
Олег Байбула Level 32, Ukraine Expert
14 January 2023
The class Book has an overridden method:

public String toString() {
            return getOutputByBookType();
        }
It is overridden becase every class in Java inherits from class Object. And every time you pass any object to (for example) System.out.println you will call toString method implicitly. So when you call System.out.println(books), you call overriden toString method and this method calls getOutputByBookType().
Krig Raseri Level 38, Dallas, United States
2 October 2022
Diego is a lil goofy guy
vhunjek Level 33, Varazdin, Croatia
23 January 2022
Verifier in OOP:Cars is very picky, it has to be exactly as is written in downloaded correct solution.
Karas Level 20, Tampa, United States
22 February 2021
Is anyone scraping for dark matter? and no more easy tasks to do? well... to the games area we go... I forgot to mention I do the same. All of the ones I can do in the browser.
Jurij Thmsn Level 29, Flensburg, Germany
4 March 2021
i do all exercises and have more than 400 dark matter left ...
Gellert Varga Level 23, Szekesfehervar, Hungary
7 March 2021
441, more precisely :-)
Kent Hervey Level 19, United States Expert
26 March 2021
621
Gellert Varga Level 23, Szekesfehervar, Hungary
26 March 2021
:-) Maybe you also did games tasks? (I did not.)
Naughtless Level 41, Olympus Mons, Mars
11 July 2021
I only have 428 >:(, how the hell did you get 441 lol.
whoseunassailable Level 28, India, India
6 March 2022
i got 1003 and i didn't even do games. What's going on?
Олег Байбула Level 32, Ukraine Expert
14 January 2023
2232 and i didn't do games.
Oliver Heintz Level 18, Mustang, United States
10 January 2021
Everyone seems to talk about that last task, which I thought was very straight forward. I must have finished it in less than 10 minutes from first looking at it. I got stuck for hours on the Books task, though, and no one in the comments seemed to think that was tough.
Andrei Level 41
4 December 2020
I am going to be dreaming Bones, Fingers and BodyParts tonight.. haha.. the last one took me maybe 1 hour or more? Sheeeesshhh... On to the next one!
Chandan Thapa Level 22, Dubai, United Arab Emirates
2 December 2020
had a tough time on the last one.. but worth it!
Brad Reed Level 19, Hartford, United States
23 July 2020
That verifier is VERY picky sometimes....
Jeanine Kimball Level 26, New London, United States
14 July 2020
I was definitely overthinking that last task. Took me longer than it should have, and initially made me doubt myself.
Brad Reed Level 19, Hartford, United States
23 July 2020
Story of my journey though this program LOL