Objective
Add more atributes and behavious to your planet classes
Instructions
- Open your Solcar System project
- Import from Lab 14a Solar System 2
- Modify each planet class as follows
- 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.
- 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.
- 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.
- Modify the applet Main2 as follows.
- Create one of each planet type at the beginning
- If the user clicks on planet, do nothing
- If the user clicks on the background, move the planet with the strongest gravitational attraction to the clicked point.
- Make sure your changes don't break the first applet.
Extra credit
- 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
- If the user clicks on planet, ask for new size, and change.
Grading
| Feature |
Points |
Out of |
Notes |
| Mass |
|
1 |
|
| Distance |
|
1 |
|
| Gravity |
|
2 |
|
| Applet |
|
4 |
|
| Size |
|
3 |
|
| Total |
|
8 |
|
Notes
Comments (0)
You don't have permission to comment on this page.