Создание TreeMap с высотой, долготой и широтой по разрешению. (Java) - PullRequest
0 голосов
/ 14 апреля 2020

Привет! Я работаю над заданием, пытаясь сгенерировать случайные данные в древовидной карте. Структура выглядит следующим образом: TreeMap> mapOfEarth = new TreeMap <> (); и это означало случайную высоту, долготу и широту в диапазоне 0-360 и от -90 до 90 широты. Пользователь вводит разрешение, например 1 и т. Д. (360 / разрешение) * (int) (180 / разрешение), что означает 64800 точек данных на карте. Это мой код: `

public void generateMap(double resolution) {
        mapOfEarth = new TreeMap<>();
        int size = (int) (360 / resolution) * (int) (180 / resolution);// this runs through and sets the amount of data points needed
        System.out.println(size);
        int count = 0;
            for (int f = 0; f < 360; f++) {
                for (int i = -90; i < 90; i++) {
                    TreeMap<Double, Double> structure = new TreeMap<>();
                    structure.put((double) f, (double) i);
                    double altitude = (new Random().nextInt());//creates next variable
                    mapOfEarth.put(altitude, structure);//adds in smaller tree map into larger one
                    count++;
                }
        }
        System.out.println(count);
            System.out.println(mapOfEarth.size());


    }

// Мой вывод генерирует правильные данные, но не применяет разрешение. Я пробовал:

  while (mapOfEarth.size() < size){
     for (int f = 0; f < 360; f++) {
                for (int i = -90; i < 90; i++) {
                    TreeMap<Double, Double> structure = new TreeMap<>();
                    structure.put((double) f, (double) i);
                    double altitude = (new Random().nextInt());//creates next variable
                    mapOfEarth.put(altitude, structure);//adds in smaller tree map into larger one
                    count++;
                }
        }
}

//I have also tried:

double altitude = (new Random(size).nextInt())
double altitude = (new Random().nextInt(size))
and also:
for (int f = 0; f < size; f++) {
 for (int i = -90; i < size; i++) {
                    TreeMap<Double, Double> structure = new TreeMap<>();
                    structure.put((double) f, (double) i);
                    double altitude = (new Random().nextInt());//creates next variable
                    mapOfEarth.put(altitude, structure);//adds in smaller tree map into larger one
                    count++;
                }
        }

Что мне делать? Это отрывки моего кода

...