"Hi, Amigo. Here are some interesting tasks involving static methods:"
A static variable exists outside an object. So if we need to calculate the number of objects created for a particular class, we can create a static class variable. Does that make sense? Let's count Cat objects using the catCount variable, which will be part of the class. We'll increment it by 1 each time the constructor is called.
Static methods for cats
The secret CodeGym center has entered into an agreement with cat breeders to supply them with applications. In particular, as beginning programmers study getters and setters, they write a cat-counting program for cat lovers. Your time has come: Create a Cat class with static methods that you will use to get or change the number of cats.
Distance between two points
You're aware that you can draw a straight line between any two points in a plane, right? Probably, but if not, check out Euclid and his treatise called "Elements". Better yet, take this assertion on faith and write a static double getDistance(x1, y1, x2, y2) method. It should calculate the distance between two points.
Today students at the secret CodeGym center received a reading assignment. They (and you) need to create a ConsoleReader class with 4 static methods: one of them reads a string from the keyboard, the second — an integer, and the third — a fractional number. The fourth is different: it reads the string "true" or "false" from the keyboard and returns the corresponding boolean value.
We love static methods. They make the inaccessible accessible. Of course, sometimes the opposite is true... But in this task, we love them: Let's create a StringHelper class that has 2 static methods: multiply(String s, int count) - returns a string that has been repeated count times; and multiply(String s) - returns a string that has been repeated 5 times.
Controlling body weight
Ellie is hysterical: she thinks she's fat. What's next? No public appearances, except perhaps with neighbors on the bench in the front yard. Buying two seats on a plane. A constantly overloaded elevator. It's so embarrassing. Destruction and misery. The world is a dark, drab swamp. Stop right there. Isn't Ellie exaggerating? Let's write a program for her that will calculate her body mass index and calm her down (or upset her).
The calculator is like a rite-of-passage in programming. Every decent noob simply must write a program that adds and subtracts. Now that we already know how to manipulate classes and static methods, we'll create a regular calculator with four arithmetic operations and even the ability to find a percentage of a number!