System.out.println();
package zh.codegym.task.task15.task1522;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
巩固单例模式
*/
public class Solution {
public static void main(String[] args) {
}
public static Planet thePlanet;
// 在此添加 static 块
static {
/*try {
Class.forName(Earth.class.getName());
Class.forName(Moon.class.getName());
Class.forName(Sun.class.getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}*/
readKeyFromConsoleAndInitPlanet();
}
public static void readKeyFromConsoleAndInitPlanet() {
// 在此实现步骤 5
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
try {
String s = r.readLine();
if(s.equalsIgnoreCase(Earth.class.getSimpleName())) {
thePlanet = Earth.getInstance();
} else if(s.equalsIgnoreCase(Moon.class.getSimpleName())) {
thePlanet = Moon.getInstance();
} else if(s.equalsIgnoreCase(Sun.class.getSimpleName())) {
thePlanet = Sun.getInstance();
} else {
//thePlanet = null;
}
//System.out.println(thePlanet);
} catch (IOException e) {
e.printStackTrace();
}
}
}