public static void main(String[] args) {
List al = new ArrayList();
int N1 ;
int N2;
double T = 2.5;
al.add("省体育中心");
al.add("王岩");
al.add("兴隆铺");
al.add("同乐");
al.add("南街新村");
al.add("海滩寺");
al.add("大石桥");
al.add("人民公园);
al.add("二七广场");
al.add("西大街");
al.add("郑州文庙");
al.add("博览中心");
al.add("凤凰台");
al.add("东十里铺");
al.add("通泰路");
al.add("西周");
al.add("省骨科医院");
System.out.println("\n"+"欢迎使用地铁系统");
System.out.println("===========================");
for(int i = 0;i < al.size();i++) {
System.out.print("第"+(i+1)+"站:"+al.get(i) +"\t");
if((i+1)%5 == 0) {
System.out.println();
}
}
System.out.println("\n"+"===========================");
do {
System.out.println("请输入上车站");
Scanner sc = new Scanner(System.in);
String name1 = sc.nextLine();
if(al.contains(name1)) {
N1 = al.indexOf(name1);
break;
}else {
System.out.println("您输入的上车站"+ name1 +"不存在!!!");
}
} while (true) ;
do {
System.out.println("请输入下车站");
Scanner sc = new Scanner(System.in);
String name2 = sc.nextLine();
if(al.contains(name2)) {
N2 = al.indexOf(name2);
break;
}else {
System.out.println("您输入的到达站:"+ name2 + "不存在");
}
} while (true) ;
if(Math.abs(N2 - N1)< 3) {
System.out.println("从" + al.get(N2) + "到" + al.get(N1) + "共经过" + Math.abs(N2 - N1) + "站," +"收费3元"+ "大约需要" + (T*Math.abs(N2 - N1)) + "分钟");
}else if(Math.abs(N2 - N1) >3 && Math.abs(N2 - N1) <= 5) {
System.out.println("从" + al.get(N2) + "到" + al.get(N1) + "共经过" + Math.abs(N2 - N1) + "站," +"收费4元"+ "大约需要" + (T*Math.abs(N2 - N1)) + "分钟");
}else {
if(4+(Math.abs(N2 - N1)-4)*2 >10) {
System.out.println("从" + al.get(N2) + "到" + al.get(N1) + "共经过" + Math.abs(N2 - N1) + "站," +"收费10元"+ "大约需要" + (T*Math.abs(N2 - N1)) + "分钟");
}else {
System.out.println("从" + al.get(N2) + "到" + al.get(N1) + "共经过" + Math.abs(N2 - N1) + "站," +"收费" +(4+(Math.abs(N2 - N1)-4)*2)+"元"+ "大约需要" + (T*Math.abs(N2 - N1)) + "分钟");
}
}
}
}
相关文章
- 02-21计应191西 一组 刘孟琦
- 02-21计应191 西 翁余孟
- 02-21计应191(西)瓮余孟 一组