package one;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;
class css {
Nature[] vexs = new Nature[20]; // 定义20个顶点(地图上的20个位置)
int[][] arcs = new int[20][20]; // 用来存取权值(地图上两个地点之间的距离)
}
public class main {
private static final int MaxInt = 22222;
private static Scanner input = new Scanner(System.in);
private static ArrayList<Nature> graph = new ArrayList<Nature>();
private static Nature n = new Nature();
private static css css = new css();// 生成一个地图对象//建立地图
public static void main(String[] args) {
boolean flag = true;
utility utility = new utility();
while (flag) {
System.out.println("********************欢迎来到湖南涉外经济学院导游系统*********************");
System.out.println("* *");
System.out.println("* 1.查询景点信息 *");
System.out.println("* 2.增加一个新景点及相关信息 *");
System.out.println("* 3.删除一个景点及其相关信息 *");
System.out.println("* 4.修改已有景点的相关信息 *");
System.out.println("* 5.增加一条新的路径 *");
System.out.println("* 6.修改一条新的路径 *");
System.out.println("* 7.删除一个路径 *");
System.out.println("* 8.查询目的地的最短路径及经过地点 *");
System.out.println("* 9.学校地图 *");
System.out.println("* A.退出 *");
System.out.println("* *");
System.out.println("********************湖南涉外经济学院导游系统*********************");
System.out.println("请选择需要的服务(1-A):");
char c = utility.readNumbers();
switch (c) {
case '1':
query();
break;
case '2':
addSopt();
break;
case '3':
deleteSpot();
break;
case '4':
alterSpot();
break;
case '5':
addRoute();
break;
case '6':
alterRoute();
break;
case '7':
deleteRoute();
break;
case '8':
searchRoute();
break;
case '9':
Map();
break;
case 'A':
System.out.println("成功退出!");
System.exit(0);
default:
System.out.println("输入有误!请重新输入!");
break;
}
System.out.println("你是否还要进入系统(Y/N)");
char c1 = utility.esitmateTest();
if (c1 == 'Y') {
} else {
flag = false;
}
}
}
public static void query() {
graph = IO.select(graph);
int flag = 0;
if (graph.size() > 0) {
System.out.println("本校景点有:");
for (Nature st : graph) {
System.out.println(st);
}
} else {
System.out.println("没有数据");
System.exit(0);
}
System.out.println("请选择您要查询的景点序号");
int select = input.nextInt();
for (int i = 0; i < graph.size(); i++) {
if (graph.get(i).getnum() == select) {
System.out.println("景点序号: " + graph.get(i).getnum() + " 景点名称: " + graph.get(i).getname() + " 景点描述: "
+ graph.get(i).getinfo());
flag = 1;
}
}
if (flag == 0) {
System.out.println("查找失败,没有此数据");
}
}
public static void alterRoute() {
graph = IO.select(graph);
if (graph.size() > 0) {
} else {
System.out.println("没有数据");
System.exit(0);
}
System.out.println("请输入修改路径的始点");
int initial = input.nextInt();
System.out.println("请输入修改路径的终点");
int destination = input.nextInt();
System.out.println("请输入修改的始点到终点的距离:");
int distance = input.nextInt();
if ((0 < initial && initial < 20) && (0 < destination && destination < 20)) {
css.arcs[initial - 1][destination - 1] = distance;
css.arcs[destination - 1][initial - 1] = distance;
System.out.println("修改路径成功!");
} else
System.out.println("您输入的位置有误!");
IO.update(graph);
}
public static void searchRoute() {
graph = IO.select(graph);
if (graph.size() > 0) {
System.out.println("本校景点有:");
for (Nature st : graph) {
System.out.println(st);
}
} else {
System.out.println("没有数据");
System.exit(0);
}
System.out.println("请输入您的位置");
int initialPosition = input.nextInt();
System.out.println("请输入您的目的地");
int targetPosition = input.nextInt();
ShortestPath_DIJ(css, initialPosition, targetPosition);
}
public static void alterSpot() {
graph = IO.select(graph);
if (graph.size() > 0) {
System.out.println("请输入您想修改哪个景点的相关信息(输入编号)");
} else {
System.out.println("没有数据");
System.exit(0);
}
int number = input.nextInt();
for (int i = 0; i < graph.size(); i++) {
if (graph.get(i).getnum() == number) {
System.out.println("请输入该景点的相关信息:");
String message = input.next();
graph.get(i).setinfo(message);
} else {
System.out.println("输入错误!");
}
}
System.out.println("修改成功!");
IO.update(graph);
}
public static void addSopt() {
System.out.println("请输入景点的序号:(1-20内按顺序写入)");
boolean fal = true;
int num = 0;
while (fal) {
num = input.nextInt();
if (num > 0 && num < 20) {
fal = false;
} else {
System.out.println("请重新输入景点的序号:(1-20内按顺序写入)");
fal = true;
}
}
System.out.println("请输入新景点的名字:");
String name = input.next();
System.out.println("请输入新景点的相关信息:");
String info = input.next();
Nature n = new Nature(num, name, info);
graph.add(n);
IO.update(graph);
System.out.println("添加景点成功!");
}
public static void addRoute() {
graph = IO.select(graph);
if (graph.size() > 0) {
} else {
System.out.println("没有数据");
System.exit(0);
}
System.out.println("请输入路径的始点");
int initial = input.nextInt();
System.out.println("请输入路径的终点");
int destination = input.nextInt();
System.out.println("请输入始点到终点的距离:");
int distance = input.nextInt();
if ((0 < initial && initial < 20) && (0 < destination && destination < 20)) {
css.arcs[initial - 1][destination - 1] = distance;
css.arcs[destination - 1][initial - 1] = distance;
System.out.println("添加路径成功!");
} else
System.out.println("您输入的位置有误!");
IO.update(graph);
}
public static void deleteSpot() {
graph = IO.select(graph);
if (graph.size() > 0) {
for (Nature st : graph) {
System.out.println(st);
}
} else {
System.out.println("没有数据");
System.exit(0);
}
System.out.println("请输入将要删除景点的标号");
int number = input.nextInt();
// 在范围内
if (date1(number)) {
for (int i = 0; i < graph.size(); i++) {
if (graph.get(i).getnum() == number) {
graph.remove(i);
break;
}
}
System.out.println("删除成功。。。");
if(graph.size()==0) {
System.out.println("没有数据");
}else {
System.out.println("删除的数据之后的数据");
}
for (Nature st : graph) {
System.out.println(st);
}
} else {
System.out.println("删除失败");
}
IO.update(graph);
}
public static boolean date1(int d) {
boolean flag = false;
for (Nature s : graph) {
if (s.num == d) {
flag = true;
break;
}
}
return flag;
}