CodeGym /Courses /Java Core /Bonus task | Lesson 8 | Level 4

Bonus task | Lesson 8 | Level 4

Java Core
Level 4 , Lesson 8
Available

"Hey, soldier!"

"Good day, Captain!"

"I've got awesome news for you. Here are some exercises to reinforce your skills. Do them every day and your skills will grow at an insane speed. They were created especially for IntelliJ IDEA."

8
Task
Java Core, level 4, lesson 8
Locked
Bridges
Create a Bridge interface with a getCarsCount() method that counts cars. Write WaterBridge and SuspensionBridge classes that implement this interface. The getCarsCount() method must return any constant int value. This value must be different for different classes.
8
Task
Java Core, level 4, lesson 8
Locked
Wine tasting
30% of the robots on Planet Soto have an alcohol dependence, which causes anxiety among the remaining 70%. More precisely, the 30% are addicted to alcohol-related programs. We are talking about robots, after all. But now it's your chance to do the same!
16
Task
Java Core, level 4, lesson 8
Locked
User, loser, coder and programmer
1. Enter a few strings (keys) from the keyboard [in a loop]. The following strings (keys) are allowed: "user", "loser", "coder", "programmer". Stop reading in strings after reading in any string that does not match one of the above. 2. For each entered string: 2.1. Create the appropriate object [see Person.java], e.g.
4
Task
Java Core, level 4, lesson 8
Locked
Implement the printMainInfo method
Write an implementation of the printMainInfo method: * If a Drawable object is passed to the method, call the draw method on the object. * If a Movable object is passed to the method, call the move method on the object.
8
Task
Java Core, level 4, lesson 8
Locked
Computer
We're using programming and OOP tools to build a new computer for work. We won't just have a Computer class. We'll also have a CompItem interface that will be implemented by the Computer class.
16
Task
Java Core, level 4, lesson 8
Locked
MovieFactory
You have the code for a MovieFactory program. Figure out what it does. Add Cartoon and Thriller classes. Understand how we get a SoapOpera object using the key "soapOpera".
8
Task
Java Core, level 4, lesson 8
Locked
Janitorial services
Let's create a virtual janitorial business with a cleanAllApartments method for all apartment types and individual methods for cleaning one-, two- and three-bedroom apartments.
8
Task
Java Core, level 4, lesson 8
Locked
Fixing bugs
Think about how CanSwim and CanWalk interfaces relate to the SeaCreature class. Create the correct inheritance relationship between the interfaces and the SeaCreature class. And how might the Orca, Whale, and RiverOtter classes relate to the SeaCreature class?
16
Task
Java Core, level 4, lesson 8
Locked
Currencies
Let's do some work with money. Your job is to expand the functionality of a program that can manipulate currencies. For the specific currencies, see the task conditions. To start, create a private double field amount in the abstract Money class...
8
Task
Java Core, level 4, lesson 8
Locked
Fix four mistakes
This code has four bugs, and your task is... Yeah, you already know what your task is. First of all, you need to figure out what the code does. Create something and fix the bugs that were written before you got involved with the code (as well as any that appear after you get involved).

"Those previous exercises were for rookies. I've added some more advanced bonus exercises for the old-timers. Just for veterans."

8
Task
Java Core, level 4, lesson 8
Locked
Exception invasion
In reality, there are oceans of exceptions in programs, and you'll eventually get used to them. You can start right now: populate the list exceptions with ten (10) different exceptions. The first exception is already implemented in the initExceptions method.
16
Task
Java Core, level 4, lesson 8
Locked
GCD
We continue our attempts to enter the cosmic space belonging to Planet Linear Chaos. Here's another task taken from a border-crossing interview, for young arrivals: find the greatest common divisor (GCD) of two positive integers.
8
Task
Java Core, level 4, lesson 8
Locked
Singleton
A class implements the Singleton pattern if it lets you create just one object of its type. You need to create a Singleton class in a separate file. Add a static getInstance method that returns the same object any time it is called. Think about how you can prevent the creation of additional instances of this class.
Comments (50)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Simphiwe Level 33, Johannesburg, South Africa
14 March 2023
Hey, does anybody know how to solve this test case "For each string entered (including the invalid string), you must call the MovieFactory.getMovie method." in the MovieFactory task.
Anonymous #10782038 Level 24, United States of America
10 April 2024
That one took me a while. basically in your while loop you check that the input in general is not null, then you assign the movie var using getMovie and then check if movie == null which means it was not one of the valid keys.
Rene Level 28, Netherlands
15 May 2024
I did no checks on the received input as the getMovie method will return null if the input is invalid (not matching one of the defined values). I call getMovie on every input and exit the loop if getMovie gives me a null value . In the loop you can proceed to print what is needed as at that point you will have received a valid object from getMovie.
Anonymous #10772722 Level 15, Clayton
14 January 2022
"Create a singleton!" they said despite never discussing how to implement one or what a singleton is. Seeing no comments of people wondering how the heck we were supposed to solve this makes me wonder if comments are being deleted. I'm not sure what the value is in having to search the web to understand something we're paying to learn.
Anonymous #10782038 Level 24, United States of America
1 April 2024
pretty common with this site. honestly I am just using this site for the excercises and learn the topic elsewhere.
Justin Smith Level 41, Greenfield, USA, United States
6 August 2021
Wow, 13 tasks on this page! Going to do all of them.
TheLordJackMC Level 39, Princeton, idk somewhere
15 July 2021
did he get demoted?
Naughtless Level 41, Olympus Mons, Mars
10 July 2021
The GCD task is buggy as hell. It wants you do do the GCD algorithm exactly like the reference solution. I implemented a GCD algorithm I got from some other website, and just used a simple if statement to check whether the numbers were negative (which is exactly what the reference did) and threw an exception if so. The verifier literally will not accept the algorithm, even if it did exactly the same thing when I tested 5 different scenarios on the code and returned the correct answers (and threw exceptions when the numbers were negative).
whoseunassailable Level 28, India, India
6 March 2022
i put my own solution instead and in my own manner and was able to properly execute the code . Took 2 attempts to pass the test but it worked like a charm.
DarthGizka Level 24, Wittenberg, Germany
4 June 2021
task1421 (Singleton) caveat: the static Singleton instance field must be named instance. This requirement is easy to overlook.
Anonymous #10853261 Level 21, United States
22 December 2021
I found this a little frustrating - more applicable feedback from codegym would have been peachy... Is the naming of the Single instance 'instance' inherent, as in a best practice that I should have already known?
Олег Байбула Level 32, Ukraine Expert
11 January 2023
I've got "Check your code. It looks like you have an infinite loop." exeption. Despite it works perfectly in the IntelliJ.
DarthGizka Level 24, Wittenberg, Germany
4 June 2021
task1416 (Fixing bugs) caveat: the test whether Whale and Orca are derived from SeaCreature and implement CanSwim is broken. I derived both from an intermediate class SeaCreatureThatCanSwim which inherits SeaCreature and implements CanSwim, but the test for the requirements regarding derivation from SeaCreature and implementation of CanSwim *failed*. So you better be good and imitate a sloppy, inept programmer in order to get your code to pass...
Jokeres Level 24, Budapest, Hungary
31 March 2021
Computer task was rly good. I love learning keycombinations to shorten things
Shilpa nori Level 34, Rochester, United States
27 January 2021
For gcd task , you just have to throw exception. It took me a while to get that alone right.
ayhem bouabid Level 25, Tunis, Tunisia
12 January 2021
Me me = new Myself(); if (me instanceof DevelopperClass) System.out.println("My life is freaking wonderful!!!");