/** * Weight Calculator > Essentials3.java * * Displays a table of calculated weights on Jupiter using console output. * Illustrates precedence and parenthesis, type cast, named constant, while loop * * @author Dale Reed */ public class Essentials3 { public static void main(String[] args) { // variable declarations int earthWeight = 100; // weight on the earth, declared and initialized int jupiterMassFactor = 318; // Jupiter has 318 times the mass of Earth int jupiterRelativeRadius = 11; // Jupiter has radius 11 times greater than Earth's // Calculate multiplier to compare earth and Jupiter weights double weightMultiplier = (double)jupiterMassFactor / (jupiterRelativeRadius * jupiterRelativeRadius); System.out.print("Multiply Earth Weight by " + weightMultiplier); System.out.print(" to find Jupiter weight. \n\n"); // display a table of weights on earth and Jupiter final int WEIGHT_INCREMENT = 20; // increment between earth weights in table rows System.out.println("Earth Jupiter "); // table heading int loopCounter = 0; // loop iterations counter while (loopCounter < 7) { System.out.print( " " + earthWeight); System.out.println( " " + (earthWeight * weightMultiplier) ); loopCounter = loopCounter + 1; // same as loopCounter++ earthWeight = earthWeight + WEIGHT_INCREMENT; // The above line is the same as: earthWeight += WEIGHT_INCREMENT; } System.out.println("\nDone."); } } /* Output: Multiply Earth Weight by 2.628099173553719 to find Jupiter weight. Earth Jupiter 100 262.8099173553719 120 315.3719008264463 140 367.9338842975207 160 420.4958677685951 180 473.05785123966945 200 525.6198347107438 220 578.1818181818182 Done. */