mardi 14 avril 2020

Generating a TreeMap with an altitude, longitude and latitude by resolution.(Java)

Hi I am working on an assignment trying to generate random data in a treemap, the stucture is like this TreeMap> mapOfEarth = new TreeMap<>(); and its meant to be a random altitude and a longatude and latitude in the range of 0-360 longatude and -90 to 90 latitude. The user inputs a resolution such as 1 and so (360 / resolution) * (int) (180 / resolution) meaning 64800 data points in the map. This is my code: `

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());


    }

// My output is generating the correct stuff such but isn't applying the resolution. I have tried:

  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++;
                }
        }

What am i to do? This is snips of my code




Aucun commentaire:

Enregistrer un commentaire