Найдите ближайшую точку от координат пользователейJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Найдите ближайшую точку от координат пользователей

Сообщение Anonymous »

Я хотел бы знать, как использовать точку, используя точку закрытия, используя координаты. Я использую хэшмап, который содержит координаты и струны. Я позволил пользователю ввести ось X и Y и сохранить их как int a и int b, но я не знаю, куда оттуда идти. Спасибо, что посмотрели < /p>

import java.util.HashMap;
import java.util.Scanner;

public class Coordinate {

static class Coords {
int x;
int y;

public boolean equals(Object o) {
Coords c = (Coords) o;
return c.x == x && c.y == y;
}

public Coords(int x, int y) {
super();
this.x = x;
this.y = y;
}

public int hashCode() {
return new Integer(x + "0" + y);
}

public String toString()
{
return x + ";" + y;
}

}

public static void main(String args[]) {

HashMap map = new HashMap();

map.put(new Coords(250, 140), "Clifton street");
map.put(new Coords(195, 115), "twoli");
map.put(new Coords(165, 95), "Jacobs well");
map.put(new Coords(140, 90), "moxbridge");
map.put(new Coords(55, 95), "parkway");
map.put(new Coords(15, 120), "easton");
map.put(new Coords(260, 25), "Weston on shore");
map.put(new Coords(250, 60), "newbridge");
map.put(new Coords(185, 85), "central");
map.put(new Coords(140, 100), "stdennis");
map.put(new Coords(85, 140), "trim bridge");
map.put(new Coords(170, 35), "windmill hill");
map.put(new Coords(150, 60), "shakespeare court");
map.put(new Coords(95, 50), "temple fields");
map.put(new Coords(55, 125), "pirac cresent");
map.put(new Coords(150, 155), "st judes hill");

Scanner input = new Scanner(System.in);
int i;
int a;
int b;

System.out.println(map.size());
System.out.println(map.toString());
Coords c = new Coords(65,72);
System.out.println(c + " - " + map.get(c));

System.out.println("choose from the following");
System.out.println("find closest station = 1");
System.out.println("plan train route = 2");
i = input.nextInt();

if (i==1){
System.out.println("enter your x axis ");
a = input.nextInt();
System.out.println("enter your y axis");
b = input.nextInt();

System.out.println("the nearest station is");
}
else if (i==2){
System.out.println("route planner");
}
else {
System.out.println("entered incorrect number");

}
}
}


Подробнее здесь: https://stackoverflow.com/questions/118 ... oordinates
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»