1 22 23 package org.jboss.cache.pojo.test; 24 25 34 @org.jboss.cache.pojo.annotation.Replicable 36 public enum EnumPlanet 37 { 38 MERCURY(3.303e+23, 2.4397e6), 39 VENUS(4.869e+24, 6.0518e6), 40 EARTH(5.976e+24, 6.37814e6), 41 MARS(6.421e+23, 3.3972e6), 42 JUPITER(1.9e+27, 7.1492e7), 43 SATURN(5.688e+26, 6.0268e7), 44 URANUS(8.686e+25, 2.5559e7), 45 NEPTUNE(1.024e+26, 2.4746e7); 46 47 private double mass; private double radius; 50 EnumPlanet() {;} 52 53 EnumPlanet(double mass, double radius) 54 { 55 this.mass = mass; 56 this.radius = radius; 57 } 58 59 public double mass() 60 { 61 return mass; 62 } 63 64 public double radius() 65 { 66 return radius; 67 } 68 69 public void setMass(double mass) 70 { 71 this.mass = mass; 72 } 73 74 public void setRadius(double radius) 75 { 76 this.radius = radius; 77 } 78 79 public static final double G = 6.67300E-11; 81 82 public double surfaceGravity() 83 { 84 return G * mass / (radius * radius); 85 } 86 87 public double surfaceWeight(double otherMass) 88 { 89 return otherMass * surfaceGravity(); 90 } 91 92 public static void main(String [] args) 93 { 94 double earthWeight = Double.parseDouble(args[0]); 95 double mass = earthWeight / EARTH.surfaceGravity(); 96 for (EnumPlanet p : EnumPlanet.values()) 97 System.out.printf("Weight on %s is %f%n", 98 p, p.surfaceWeight(mass)); 99 } 100 } 101 | Popular Tags |