mardi 13 octobre 2020

Initialize a random array with another random array

I am trying to create an array of 4 and randomize it, however, when trying to add to the constructor another random array it gives me NULL.

note no all paramaters are random, first Im trying to figure out how to pass cars array to circuit.

code:

Car[] cars = new Car[10];
    for (int i = 0; i < cars.length; i++) {
        cars[i] = new Car("Mitsubishi", 1970, drivers);
        
    }
    
    Circuit[] maslul = new Circuit[4];
    for (int i = 0; i < maslul.length; i++) {
        for (int j = 0; j < cars.length; j++) {
            maslul[i] = new Circuit("France Circuit", countries[rand.nextInt(5) + 1], 12, cars);
            
        }
        System.out.println(maslul[i].toString());

what i get:

Name of circuit: France Circuit, Country: UK, Length of circuit: 12, Cars: null



Aucun commentaire:

Enregistrer un commentaire