"Hei, soldat!"
"God dag, kaptein!"
"Jeg har fantastiske nyheter til deg. Her er noen øvelser for å forsterke ferdighetene dine. Gjør dem hver dag og ferdighetene dine vil vokse i en vanvittig hastighet. De ble laget spesielt for IntelliJ IDEA."
"De tidligere øvelsene var for nybegynnere. Jeg har lagt til noen mer avanserte bonusøvelser for oldtimers. Bare for veteraner."
16
Oppgave
Java Core, nivå, lekse
Different methods for different types
So, polymorphism. You haven't forgotten about it, have you? Good. Then let's complete the following task: Read data from the console until the word "exit" is entered. For each value (except "exit"), call the print method. The correct print method depends on the value. For example, if the value contains a period, then use the print method for Double. If the value is a number between 0 and 128, then use the method for short.
4
Oppgave
Java Core, nivå, lekse
Brain training
Find the error in the logic: Duck should correctly implement the CanMove interface. Fix the error so you get the correct result.
8
Oppgave
Java Core, nivå, lekse
OOP: Method overloading
Overload the Tree class's info(Object s) method twice to get 3 methods: info(Object s), info(Number s), and info(String s). Then study the info(Object s) method and create similar functionality in the new methods. For example, the result for the info(Number s) method might be: "Tree No. 123, Number method, parameter Short.
16
Oppgave
Java Core, nivå, lekse
Reinforce the singleton pattern
Let's delve into the singleton pattern by considering the sun and planets of the solar system. First, do an Internet search and find some example of "lazy initialization" using the singleton pattern. Create three singleton classes "in its likeness and image": Sun, Moon and Earth. Then implement the Planet interface in them. And do a couple other operations.
8
Oppgave
Java Core, nivå, lekse
Overloading constructors
In this task, we need to create the Solution class and its descendant SubSolution. We need to create constructors for this descendant and fix their access modifiers so that we get three constructors with different modifiers (except private).
8
Oppgave
Java Core, nivå, lekse
Order of loading variables
Time for a useful debugging task. You have code you need to dig into: figure out what gets initialized and in what order. You can do this using the IntelliJ IDEA debugger and breakpoints. Then fix the initialization order so you get a specific result.
8
Oppgave
Java Core, nivå, lekse
File in a static block
Initialize the variable Statics.FILE_NAME to the full path to a data file that contains several lines. Then, in the static block, read all the lines from the file named Statics.FILE_NAME, and add them separately to the List lines.
8
Oppgave
Java Core, nivå, lekse
Debug, debug, and again debug
Again and again, we search for other people's mistakes and correct them... That's our lot in life as programmers. Our program again displays something wrong: An bug has crept in (just one!). Find it and neutralize it! Use the IntelliJ IDEA debugger to do this.
16
Oppgave
Java Core, nivå, lekse
Request parser
Read a URL from the console. Then display a space-delimited list of all the parameters (The parameters follow the "?" and are separated by "&", e.g. "lvl=15"). The URL contains at least 1 parameter. If the obj parameter is present, pass its value to the relevant alert method.
8
Oppgave
Java Core, nivå, lekse
OOP: The Euro is money too
Correct the Euro class to avoid a StackOverflowError. And, strange as it may seem, the Euro should inherit the Money class, which should implement the getAmount method.
8
Oppgave
Java Core, nivå, lekse
Mastering the static block
Let's create Plane and Helicopter classes that implement the CanFly interface. Then in the Solution class's static method, we need to read a String from the console. If it's equal to "helicopter" ("plane"), we'll assign a Helicopter (Plane) object to the static CanFly field result. In the static block, initialize the CanFly field result by calling the reset method.
8
Oppgave
Java Core, nivå, lekse
Template pattern
Let's create an algorithm for baristas in the DrinkMaker class. It will choose a suitable cup, add ingredients, and pour liquid. Also, we'll inherit DrinkMaker to create highly specialized algorithms for tea and latte.
8
Oppgave
Java Core, nivå, lekse
Factorial
On Planet Linear Chaos, infants are expected to find the factorial of two-digit numbers. Well, we'll behave like adults, like programmers, and write a method that calculates factorials up to the entered number.