[1725989] | 1 | import java.io.*; |
---|
| 2 | |
---|
| 3 | public class testP2 { |
---|
| 4 | public enum Planet { |
---|
| 5 | // mass radius |
---|
| 6 | MERCURY ( 3.303e+23, 2.4397e6 ), |
---|
| 7 | VENUS ( 4.869e+24, 6.0518e6 ), |
---|
| 8 | EARTH ( 5.976e+24, 6.37814e6 ), |
---|
| 9 | MARS ( 6.421e+23, 3.3972e6 ), |
---|
| 10 | JUPITER ( 1.9e+27, 7.1492e7 ), |
---|
| 11 | SATURN ( 5.688e+26, 6.0268e7 ), |
---|
| 12 | URANUS ( 8.686e+25, 2.5559e7 ), |
---|
| 13 | NEPTUNE ( 1.024e+26, 2.4746e7 ); |
---|
| 14 | |
---|
| 15 | private final double mass; // in kilograms |
---|
| 16 | public final double radius; // in meters |
---|
| 17 | |
---|
| 18 | Planet( double mass, double radius ) { |
---|
| 19 | this.mass = mass; this.radius = radius; |
---|
| 20 | } |
---|
| 21 | } |
---|
| 22 | static double mass( Planet p ) { return p.mass; } |
---|
| 23 | static double radius( Planet p ) { return p.radius; } |
---|
| 24 | |
---|
| 25 | static double surfaceGravity( Planet p ) { |
---|
| 26 | return 6.67300E-11 * p.mass / ( p.radius * p.radius ); |
---|
| 27 | } |
---|
| 28 | static double surfaceWeight( Planet p, double otherMass ) { |
---|
| 29 | return otherMass * surfaceGravity( p ); |
---|
| 30 | } |
---|
| 31 | public static void main( String[] args ) { |
---|
| 32 | if ( args.length != 1 ) { |
---|
| 33 | System.err.println( "Usage: java Planet <earth_weight>" ); |
---|
| 34 | System.exit( -1 ); |
---|
| 35 | } |
---|
| 36 | Planet day = Planet.valueOf( "EARTH" ); |
---|
| 37 | System.out.println( day.ordinal() + " " + day.name() + " " + day.mass + " " + day.radius + " " + Planet.valueOf( "EARTH" ) ); // 5 Sat |
---|
| 38 | |
---|
| 39 | double earthWeight = Double.parseDouble( args[0] ); |
---|
| 40 | double mass = earthWeight / surfaceGravity( Planet.EARTH ); |
---|
| 41 | for ( Planet p : Planet.values() ) |
---|
| 42 | System.out.printf( "Your weight on %s is %f%n", p, surfaceWeight( p, mass ) ); |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | // java test |
---|