Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. public class SolarModel {
  2.  
  3. public static void main(String[] args){
  4. SolarSystem model = new SolarSystem(700, 700);
  5.  
  6. /* Create new instances of each object in the solar system */
  7. SunObject sun = new SunObject(0, 0, 50, "YELLOW", 0);
  8. PlanetObject mercury = new PlanetObject(60, 30, 15, "LIGHT_GRAY" ,5);
  9. PlanetObject venus = new PlanetObject(90, 30, 15, "GREEN", 3);
  10. PlanetObject earth = new PlanetObject(140, 30, 15, "BLUE", 2);
  11. PlanetObject mars = new PlanetObject(180, 30, 15, "RED", 1.2);
  12.  
  13. MoonObject moon = new MoonObject(15, 30, 2, "WHITE", 1.5);
  14.  
  15. while(true){
  16. /*Draw all the planets onto the SolarSystem model */
  17. model.drawSolarObject(sun.getDistance(), sun.getAngle(), sun.getDiameter(), sun.getColour());
  18. model.drawSolarObject(mercury.getDistance(), mercury.move(), mercury.getDiameter(), mercury.getColour());
  19. model.drawSolarObject(venus.getDistance(), venus.move(),venus.getDiameter(), venus.getColour());
  20. model.drawSolarObject(earth.getDistance(), earth.move(), earth.getDiameter(), earth.getColour());
  21. model.drawSolarObject(mars.getDistance(), mars.move(), mars.getDiameter(), mars.getColour());
  22.  
  23. /* Draw the Earth's moon.
  24. * Use the Earth's PointInSpace as a point in which the moon orbits around
  25. */
  26. model.drawSolarObjectAbout(moon.getDistance(),moon.getAngle() + moon.move(), moon.getDiameter(), moon.getColour(),
  27. earth.getDistance(), earth.getAngle());
  28.  
  29. /* Draw Mars's moon.
  30. * Use Mars's PointInSpace as a point in which the moon orbits around
  31. */
  32. model.drawSolarObjectAbout(moon.getDistance(), moon.getAngle() + moon.move(), moon.getDiameter(), moon.getColour(),
  33. mars.getDistance(), mars.getAngle());
  34.  
  35. model.finishedDrawing();
  36. }
  37. }
  38.  
  39. }
  40.  
  41. public class PointInSpace {
  42.  
  43. private double distance;
  44. private double angle;
  45. private double diameter;
  46. private String colour;
  47. private double speed;
  48.  
  49. public double getDistance(){
  50. return distance;
  51. }
  52. public double getAngle(){
  53. return angle;
  54. }
  55. public double getDiameter(){
  56. return diameter;
  57. }
  58. public String getColour(){
  59. return colour;
  60. }
  61. public double getSpeed(){
  62. return speed;
  63. }
  64.  
  65. public double move(){
  66. angle += speed;
  67. return angle;
  68. }
  69.  
  70. public PointInSpace(double distance, double angle, double diameter, String colour, double speed){
  71. this.distance = distance;
  72. this.angle = angle;
  73. this.diameter = diameter;
  74. this.colour = colour;
  75. this.speed = speed;
  76. }
  77.  
  78. }
  79.  
  80. public SunObject(double distance, double angle, double diameter, String colour, double speed){
  81. super(distance, angle, diameter, colour, speed);
  82.  
  83. }
  84. }
  85. public PlanetObject(double distance, double angle, double diameter, String colour, double speed){
  86. super(distance, angle, diameter, colour, speed);
  87.  
  88. }
  89. }
  90. public MoonObject(double distance, double angle, double diameter, String colour, double speed){
  91. super(distance, angle, diameter, colour, speed);
  92.  
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement