Guest User

Solar System Model

a guest
Sep 28th, 2012
679
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package solarsystem;
  2.  
  3. import java.util.Observable;
  4.  
  5. public class SolarSystemModel extends Observable {
  6.    
  7.     public static final int DAYS_PER_EARTH_REVOLUTION_AROUND_SUN = 365;
  8.     public static final int HOURS_PER_EARTH_REVOLUTION_AROUND_AXIS = 24;
  9.    
  10.     // http://en.wikipedia.org/wiki/Orbit_of_the_Moon
  11.     // "The orbit of the Moon around the Earth is completed in approximately 27.3 days"
  12.     public static final float DAYS_PER_MOON_ORBIT_AROUND_EARTH = 27.3f;
  13.    
  14.    
  15.    
  16.     private int day;
  17.     private int hour;
  18.  
  19.     public int getDay() {
  20.         return day;
  21.     }
  22.  
  23.     public void setDay(int day) {
  24.         int oldDay = this.day;
  25.         this.day = clampDay(day);
  26.         if (oldDay != this.day) {
  27.             setChanged();
  28.             notifyObservers();
  29.         }
  30.     }
  31.  
  32.     public int getHour() {
  33.         return hour;
  34.     }
  35.  
  36.     public void setHour(int hour) {
  37.         int oldHour = this.hour;
  38.         this.hour = clampHour(hour);
  39.         if (oldHour != this.hour) {
  40.             setChanged();
  41.             notifyObservers();
  42.         }
  43.     }
  44.    
  45.    
  46.    
  47.     private int clampDay(int day) {
  48.         return day % DAYS_PER_EARTH_REVOLUTION_AROUND_SUN;
  49.     }
  50.    
  51.     private int clampHour(int hour) {
  52.         return hour % HOURS_PER_EARTH_REVOLUTION_AROUND_AXIS;
  53.     }
  54.    
  55.    
  56. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×