Validation in IDEA shows me that
But I double-checked the method and feel sure that it works as required
package com.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
Reinforce the singleton pattern
*/
public class Solution {
public static void main(String[] args) {
}
public static Planet thePlanet;
static {
readKeyFromConsoleAndInitPlanet();
}
// Add static block here
public static void readKeyFromConsoleAndInitPlanet() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
String s = reader.readLine();
switch (s) {
case Planet.SUN: {
thePlanet = Sun.getInstance();
}
case Planet.MOON: {
thePlanet = Moon.getInstance();
}
case Planet.EARTH: {
thePlanet = Earth.getInstance();
}
default:
thePlanet = null;
}
} catch (IOException e) {
e.printStackTrace();
}
// Implement step #5 here
}
}