Can seem to figure out, what they mean by: "The readKeyFromConsoleAndInitPlanet method must correctly update the value of the variable thePlanet according to the task conditions." Anyone who can help?
package com.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Reinforce the singleton pattern
1. Find an example of the singleton pattern used for lazy initialization.
Use your favorite search engine (such as Google).
2. In separate files, create three singleton classes in its likeness and image: Sun, Moon, and Earth.
3. Implement the Planet interface in the Sun, Moon, and Earth classes.
4. In Solution class's static block, call the readKeyFromConsoleAndInitPlanet method.
5. Implement the readKeyFromConsoleAndInitPlanet method:
5.1. Read one String value from the console.
5.2. If the value is equal to one of the Planet interface's constants, create a corresponding object
and assign it to Planet thePlanet, otherwise set the Planet thePlanet to null.
*/
public class Solution {
public static void main(String[] args) {}
public static Planet thePlanet;
static {
readKeyFromConsoleAndInitPlanet();
}
public static void readKeyFromConsoleAndInitPlanet() {
// Implement step #5 here
BufferedReader reader = new BufferedReader(
new InputStreamReader(System.in)
);
try {
String input = reader.readLine();
if (input.equals(Planet.SUN)) {
thePlanet = Sun.getInstance();
}
if (input.equals(Planet.MOON)) {
thePlanet = Moon.getInstance();
}
if (input.equals(Planet.EARTH)) {
thePlanet = Earth.getInstance();
} else {
thePlanet = null;
}
} catch (IOException e) {
System.out.println(e);
}
}
}