import java.util.HashMap;
import java.util.Map;
public class Functions {
public static boolean isLannisterSoldier(String color, String shield) {
return ("red".equals(color) && shield.isEmpty()) || ("lion".equals(shield));
}
public static String parentFor(String child, String parent) throws RuntimeException {
if (parent == null) {
parent = "mother";
}
Map parents = new HashMap<>();
switch (child) {
case "Daenerys Targaryen":
parents.put("mother", "Rhaella Targaryen");
parents.put("father", "Aerys II Targaryen");
return parents.get(parent);
case "Cersei Lannister":
parents.put("father", "Tywin Lannister");
return parents.get(parent);
case "Joffrey Baratheon":
parents.put("mother", "Cersei Lannister");
return parents.get(parent);
default:
throw new RuntimeException("Wrong child's name " + child);
}
}
public static String parentFor(String child) throws RuntimeException {
return parentFor(child, null);
}
public static int calculateDistanceBetweenTowns(String path) throws RuntimeException {
if (!path.contains("-")) {
throw new RuntimeException("Wrong format: " + path + ". Expected city1-city2.");
}
String[] towns = path.split("-");
return calculateDistance(towns[0], towns[1]);
}
public static int calculateDistance(String source, String dest) throws RuntimeException {
String w = "Winterfell";
String t = "The Twins";
String e = "The Eyrie";
String q = "Qarth";
String d = "Vaes Dothrak";
if (w.equals(source) && t.equals(dest) || t.equals(source) && w.equals(dest)) {
return 60;
} else if (t.equals(source) && e.equals(dest) || e.equals(source) && t.equals(dest)) {
return 20;
} else if (q.equals(source) && d.equals(dest) || d.equals(source) && q.equals(dest)) {
return 125;
}
throw new RuntimeException("Unknown cities: " + source + " and " + dest + ". Please check the names.");
}
public static String repeat(String text, int count) {
return text.repeat(count);
}
}