Hello, I'm just learning to use enums at the moment. I've got this code below and was wondering what if the words in capital letters are java objects? I think they are, as I can use the dot operator on them in the main method, but in the code there is no Planet MERCURY = new Planet() etc.
public enum Planet
{
MERCURY(3.03E23, 2.43E6),
VENUS(4.68E24, 6.05E6),
EARTH(5.96E24, 6.37E6),
MARS(6.42E23, 3.39E6),
JUPITER(1.9E27, 7.14E7),
SATURN(5.68E26, 6.02E7),
URANUS(8.68E25, 2.55E7),
NEPTUNE(1.02e26, 2.47E7);
private final double mass;
private final double radius;
public static final double G=6.67e-11;
private Planet(double mass, double radius)
{
this.mass=mass;
this.radius=radius;
}
public double surfaceGravity()
{
return G*mass/(radius*radius);
}
public double surfaceWeight(double otherMass)
{
return otherMass*surfaceGravity();
}
public static void main (String [] args)
{
System.out.println(JUPITER.radius);
System.out.println(EARTH.mass);
System.out.println(MERCURY.surfaceGravity());
System.out.println(NEPTUNE.surfaceGravity());
}
}