package test;
import java.util.HashMap;
/**
* @author 欧阳
* @date 2022/3/18
*/
public class Demo19 {
public static void main(String[] args) {
Integer distance = distance("B4", "A6");
System.out.println(distance);
System.out.println(money(distance));
}
public static double money(Integer distance){
if(distance <= 3 & distance > 0){
return 2.0;
}
if(distance > 3 & distance <= 7){
return 2 + (distance - 3) * 1.0;
}
if(distance > 7){
return 6 + (distance - 7) * 0.5;
}
return 0;
}
public static Integer distance(String A , String B){
HashMap<String, Integer> map = new HashMap<>();
map.put("B1", -7);map.put("B2", -4);map.put("B3", 0);map.put("B4", 2);map.put("B5", 3);map.put("B6", 4);map.put("B7", 7);map.put("B8", 9);map.put("B9", 14);
map.put("B10", 15);map.put("B11", 18);map.put("B12", 20);map.put("A1", 13);map.put("A2", 11);map.put("A3", 8);map.put("A4", 2);map.put("A5", 0);map.put("A6", -2);map.put("A7", -5);map.put("A8", -6);map.put("A9", -15);
Integer a = map.get(A);
Integer b = map.get(B);
if(A.startsWith("A") & B.startsWith("A") || A.startsWith("B") & B.startsWith("B")){
if((a > 0 & b > 0)){
return (a - b) > 0 ? a - b : b - a;
}
else if(a < 0 & b < 0){
return (a < b) ? -a - -b : -b - -a;
}else {
return a < 0 ? b - a : a - b;
}
}
if(a < 0 & b < 0){
return -a + -b;
}else {
return a < 0 ? b - a : a - b;
}
}
}