模仿学生管理系统写了一个城市管理系统,想使用坐标xy的方式记录每个城市坐标,如果想要实现一个功能为输入当前坐标和半径来查找周围城市该怎么取出map中的数据来进行计算呢?(都是字符串数据,会经过类型转换)
这是部分代码:
public PlaneManage() {
readFile();
if(this.map.isEmpty()) {
this.map.put("1001", new City("1001", "长春", "10", "20"));
this.map.put("1002", new City("1002", "北京", "15", "25"));
this.map.put("1003", new City("1003", "黑龙江", "13", "26"));
}
}
public void saveFile() {
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try {
fileOutputStream = new FileOutputStream(new File(path));
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject(this.map);
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}finally {
if(fileOutputStream != null) {
try {
fileOutputStream.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
}
public Map<String, City> readFile() {
FileInputStream fileInputStream = null;
ObjectInputStream objectInputStream = null;
try {
File file = new File(path);
if(file.exists()) {
fileInputStream = new FileInputStream(file);
objectInputStream = new ObjectInputStream(fileInputStream);
this.map = (Map<String, City>)objectInputStream.readObject();
}
}catch (FileNotFoundException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}catch(ClassNotFoundException e) {
e.printStackTrace();
}finally {
if(fileInputStream != null) {
try {
fileInputStream.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
return this.map;
}
下半段是雷达扫描的方法 没有写全 有大神知道怎么写么 求助了
public void radarscan(String info) {
String[] infos1 = info.split("-");
if(infos1 != null && infos1.length ==3) {
String x1 = infos1[0];
String y1 = infos1[1];
String z = infos1[2];
int[] arr = new int[infos1.length];
for (int i = 0; i < infos1.length; i++) {
arr[i] = Integer.parseInt(infos1.toString());
}
}
}