Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SolarModel {
- public static void main(String[] args){
- SolarSystem model = new SolarSystem(700, 700);
- /* Create new instances of each object in the solar system */
- SunObject sun = new SunObject(0, 0, 50, "YELLOW", 0);
- PlanetObject mercury = new PlanetObject(60, 30, 15, "LIGHT_GRAY" ,5);
- PlanetObject venus = new PlanetObject(90, 30, 15, "GREEN", 3);
- PlanetObject earth = new PlanetObject(140, 30, 15, "BLUE", 2);
- PlanetObject mars = new PlanetObject(180, 30, 15, "RED", 1.2);
- MoonObject moon = new MoonObject(15, 30, 2, "WHITE", 1.5);
- while(true){
- /*Draw all the planets onto the SolarSystem model */
- model.drawSolarObject(sun.getDistance(), sun.getAngle(), sun.getDiameter(), sun.getColour());
- model.drawSolarObject(mercury.getDistance(), mercury.move(), mercury.getDiameter(), mercury.getColour());
- model.drawSolarObject(venus.getDistance(), venus.move(),venus.getDiameter(), venus.getColour());
- model.drawSolarObject(earth.getDistance(), earth.move(), earth.getDiameter(), earth.getColour());
- model.drawSolarObject(mars.getDistance(), mars.move(), mars.getDiameter(), mars.getColour());
- /* Draw the Earth's moon.
- * Use the Earth's PointInSpace as a point in which the moon orbits around
- */
- model.drawSolarObjectAbout(moon.getDistance(),moon.getAngle() + moon.move(), moon.getDiameter(), moon.getColour(),
- earth.getDistance(), earth.getAngle());
- /* Draw Mars's moon.
- * Use Mars's PointInSpace as a point in which the moon orbits around
- */
- model.drawSolarObjectAbout(moon.getDistance(), moon.getAngle() + moon.move(), moon.getDiameter(), moon.getColour(),
- mars.getDistance(), mars.getAngle());
- model.finishedDrawing();
- }
- }
- }
- public class PointInSpace {
- private double distance;
- private double angle;
- private double diameter;
- private String colour;
- private double speed;
- public double getDistance(){
- return distance;
- }
- public double getAngle(){
- return angle;
- }
- public double getDiameter(){
- return diameter;
- }
- public String getColour(){
- return colour;
- }
- public double getSpeed(){
- return speed;
- }
- public double move(){
- angle += speed;
- return angle;
- }
- public PointInSpace(double distance, double angle, double diameter, String colour, double speed){
- this.distance = distance;
- this.angle = angle;
- this.diameter = diameter;
- this.colour = colour;
- this.speed = speed;
- }
- }
- public SunObject(double distance, double angle, double diameter, String colour, double speed){
- super(distance, angle, diameter, colour, speed);
- }
- }
- public PlanetObject(double distance, double angle, double diameter, String colour, double speed){
- super(distance, angle, diameter, colour, speed);
- }
- }
- public MoonObject(double distance, double angle, double diameter, String colour, double speed){
- super(distance, angle, diameter, colour, speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement