The usual pattern would be: public static final
. That is a globally accessible and unmodifiable array reference:
public class GravityV1 {
public static final String[] PLANETS = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Pluto"};
public static final int[] DIAMETERS = { 4876, 12107, 12755, 6794, 142983, 120536, 51117, 49527, 2390};
public static final double[] MASSES = { 3.30e23, 4.87e24, 5.97e24, 6.42e23, 1.90e27, 5.69e26, 8.66e25, 1.03e26, 1.31e22};
// ...
Note, that the naming conventions ask for capital names for constants (final statics). And that storing the three properties in three different array is not the best design. You should introduce a new class that holds those properties for each planet. Something like
public class Planet {
private String name;
private double mass;
private int diameter;
// Constructor
// getters for the three fields
}
2
solved I can not make the array global