Refs
Http://stackoverflow.com/questions/469287/c-sharp-vs-java-enum-for-those-new-to-c
Java
public enum Planet {MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), Earth (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), Uranus (8.686E+25, 2).
5559E7), NEPTUNE (1.024e+26, 2.4746e7), PLUTO (1.27e+22, 1.137e6); Private final double mass; In kilograms private final double radius;
In meters Planet (double mass, double radius) {this.mass = mass;
This.radius = radius;
public double mass () {return mass;}
Public double radius () {return radius;}
Universal gravitational constant (M3 kg-1 s-2) public static final Double G = 6.67300E-11;
Public double surfacegravity () {return G * mass/(RADIUS * radius);
Public double surfaceweight (double othermass) {return othermass * surfacegravity (); }//Example usage (slight modification of Sun ' s Example): public static void Main (string[) args) {Planet Pearth = Planet.eArth; Double Earthradius = Pearth.radius (); Just threw it in to show the usage//Argument passed in the earth Weight.
Calculate weight on each planet:double Earthweight = double.parsedouble (Args[0]);
Double mass = earthweight/pearth.surfacegravity (); For (Planet p:planet.values ()) System.out.printf ("Your weight on%s is%f%n", p, P.surfa
Ceweight (mass)); }//Example output: $ java Planet 175 Your weight on MERCURY is 66.107583 Your ' weight on VENUS is 158.374842 [etc ...]
C#
Using System;
Using System.Collections.Generic; Namespace ConsoleApplication1 {class Program {static void Main (string[] args) {plan
ET pearth = Planet.mercury; Double Earthradius = Pearth.radius; Just threw it in to show usage double earthweight = double.
Parse ("123");
Double mass = earthweight/pearth.surfacegravity (); foreach (Planet p in Planet.values) Console.WriteLine ("Your weight on {0} is {1}", p, p.surfaceweight (mass
));
Console.readkey (); } public class Planet {public static readonly Planet MERCURY = new Planet ("MERCURY", 3.303e+23, 2.)
4397E6);
public static readonly Planet VENUS = new Planet ("VENUS", 4.869e+24, 6.0518e6);
public static readonly Planet the earth = new Planet ("Earth", 5.976e+24, 6.37814e6);
public static readonly Planet mars = new Planet ("Mars", 6.421e+23, 3.3972e6); public static Readonly Planet JUPITER = new Planet ("JUPITER", 1.9e+27, 7.1492e7);
public static readonly Planet SATURN = new Planet ("SATURN", 5.688e+26, 6.0268e7);
public static readonly Planet uranus = new Planet ("Uranus", 8.686E+25, 2.5559e7);
public static readonly Planet NEPTUNE = new Planet ("NEPTUNE", 1.024e+26, 2.4746e7);
public static readonly Planet Pluto = new Planet ("PLUTO", 1.27e+22, 1.137e6); public static ienumerable<planet> Values {get {yield return Mercur
Y
Yield return VENUS;
Yield return to the Earth;
Yield return MARS;
Yield return JUPITER;
Yield return SATURN;
Yield return Uranus;
Yield return NEPTUNE;
Yield return PLUTO;
} private readonly string name; Private readonly double mass; In kilograms private readonly double RAdius;
In meters Planet (string name, double mass, double radius) {this.name = name;
This.mass = mass;
This.radius = radius;
public string Name {get {
Public double Mass {get {return Mass;}}
Public double radius {get {return Radius;}}
Universal gravitational constant (M3 kg-1 s-2) Public Const double G = 6.67300E-11;
Public double surfacegravity () {return G * mass/(RADIUS * radius);
Public double surfaceweight (double othermass) {return othermass * surfacegravity ();
public override string ToString () {return name; }
}
}