Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package solarsystem;
- import java.util.Observable;
- public class SolarSystemModel extends Observable {
- public static final int DAYS_PER_EARTH_REVOLUTION_AROUND_SUN = 365;
- public static final int HOURS_PER_EARTH_REVOLUTION_AROUND_AXIS = 24;
- // http://en.wikipedia.org/wiki/Orbit_of_the_Moon
- // "The orbit of the Moon around the Earth is completed in approximately 27.3 days"
- public static final float DAYS_PER_MOON_ORBIT_AROUND_EARTH = 27.3f;
- private int day;
- private int hour;
- public int getDay() {
- return day;
- }
- public void setDay(int day) {
- int oldDay = this.day;
- this.day = clampDay(day);
- if (oldDay != this.day) {
- setChanged();
- notifyObservers();
- }
- }
- public int getHour() {
- return hour;
- }
- public void setHour(int hour) {
- int oldHour = this.hour;
- this.hour = clampHour(hour);
- if (oldHour != this.hour) {
- setChanged();
- notifyObservers();
- }
- }
- private int clampDay(int day) {
- return day % DAYS_PER_EARTH_REVOLUTION_AROUND_SUN;
- }
- private int clampHour(int hour) {
- return hour % HOURS_PER_EARTH_REVOLUTION_AROUND_AXIS;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement