SHARE
TWEET

Solar System Model

a guest Sep 28th, 2012 539 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
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