SHARE
TWEET

Untitled

a guest Dec 9th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public enum Planet {
  2.     MERKUR(3.303e+23, 2.4397e6), VENERA(4.869e+24, 6.0518e6), ZEMLJA(5.976e+24, 6.37814e6), MARS(6.421e+23, 3.3972e6),
  3.     JUPITER(1.9e+27, 7.1492e7), SATURN(5.688e+26, 6.0268e7), URAN(8.686e+25, 2.5559e7), NEPTUN(1.024e+26, 2.4746e7);
  4.  
  5.     // gravitacijska konstanta (m3 kg-1 s-2)
  6.     public static final double G = 6.67300E-11;
  7.     private final double masa; // v kilogramih
  8.     private final double radij; // v metrih
  9.  
  10.     private Planet(double masa, double radij) { // private ali nič
  11.         this.masa = masa;
  12.         this.radij = radij;
  13.     }
  14.  
  15.     private double masa() {
  16.         return masa;
  17.     }
  18.  
  19.     private double radij() {
  20.         return radij;
  21.     }
  22.  
  23.     double surfaceGravity() {
  24.         return G * masa / (radij * radij);
  25.     }
  26.  
  27.     double surfaceWeight(double otherMass) {
  28.         return otherMass * surfaceGravity();
  29.     }
  30.  
  31.     public static void main(String[] args) {
  32.         if (args.length != 1) {
  33.             System.err.println("Uporaba: java Planet <earth_weight>, tezo podaj v kilogramih.");
  34.             System.exit(-1);
  35.         }
  36.         double tezaNaZemlji = Double.parseDouble(args[0]);
  37.         double masa = tezaNaZemlji / ZEMLJA.surfaceGravity();
  38.         for (Planet p : Planet.values())
  39.             System.out.printf("Tvoja teza na planetu %s je %f%n", p, p.surfaceWeight(masa));
  40.     }
  41.  
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top