View
 

Lab 14a: Solar System 2

Page history last edited by Mr. Kretsch 4 months ago

Objective

Add more atributes and behavious to your planet classes

Instructions

  1. Open your Solcar System project
  2. Import from Lab 14a Solar System 2
  3. Modify each planet class as follows
    1. Add a method called getMass. This method will return an integer which is the mass of the planet. The mass is proportional to the planet's area. Also, Rocky planets have more mass that similarly sized Gaseous planets.
    2. Add a method called getDistance. This method accepts a Location object as a parameter and returns the distance from the parameter point to the upper-left corner of the planet.
    3. Add a method called getGravity. This method also accepts a Location  object and returns the gravitational attraction between the parameter point and the planet. Remember that gravity is directly related to mass and inversely related to distance. 
  4. Modify the applet Main2 as follows.
    1. Create one of each planet type at the beginning 
    2. If the user clicks on planet, do nothing
    3. If the user clicks on the background, move the planet with the strongest gravitational attraction to the clicked point. 
  5. Make sure your changes don't break the first applet. 

Extra credit

  1. Add a setSize method that takes one parameter, the new size of the planet. The method changes the planet to the parameter size, making sure, of course, that the new size is valid and that the moon and rings are also sized accordingly
  2. If the user clicks on planet, ask for new size, and change.

Grading

Feature  Points  Out of  Notes 
Mass     
Distance     
Gravity     
Applet   4  
Size   3  
Total   8  

 

Notes

 
 
 
 
 
 

 

 

Comments (0)

You don't have permission to comment on this page.