The readKeyFromConsoleAndInitPlanet method must correctly update the value of the variable thePlanet according to the task conditions.
Cannot see where I make misake. Please help
package pl.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Praca nad wzorcem projektowym singleton
*/
public class Solution {
public static void main(String[] args) {
}
public static Planet thePlanet;
static {
readKeyFromConsoleAndInitPlanet();
}
public static void readKeyFromConsoleAndInitPlanet() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
String read = reader.readLine();
if (read.equals("sun")) {
thePlanet = Sun.getInstance();
}
if (read.equals("earth")) {
thePlanet = Earth.getInstance();
}
if (read.equals("moon")) {
thePlanet = Moon.getInstance();
}
else {
}
}
catch (IOException e) {
System.out.println(e);
}
}
}
/*1. Znajdź przykład wzorca singleton używanego w celu leniwej inicjalizacji. Użyj swojej ulubionej wyszukiwarki (np. Google).
2. Utwórz w osobnych plikach trzy klasy singleton na jego obraz i podobieństwo: Sun, Moon i Earth.
3. Zaimplementuj interfejs Planet w klasach Sun, Moon i Earth.
4. W bloku statycznym klasy Solution wywołaj metodę readKeyFromConsoleAndInitPlanet.
5. Zaimplementuj metodę readKeyFromConsoleAndInitPlanet:
5.1. Odczytaj z konsoli jedną wartość typu String.
5.2. Jeśli wartość jest równa jednej ze stałych interfejsu Planet, utwórz odpowiedni obiekt i przypisz go do Planet thePlanet, w przeciwnym razie ustaw Planet thePlanet na null.
*/