10.4 Designing and Implementing a Sun Class

Our task in this chapter is to construct a software model of a planetary system. To do so, we need to consider not just the planets that might be present, but the most important member of the system—the sun. We will consider the sun to be similar to a planet, in that it is a large, round, celestial body. It will certainly have some of the same characteristics as planets, including a name, mass, and radius. However, because the sun is at the center of the solar system, it will not have any distance measure. In addition, the sun provides heat and light that can be characterized by the temperature on the surface.

Given that description, we can create a Sun class using the same pattern that we followed for the Planet class. Our constructor will require values for the name, mass, radius, and temperature. LISTING 10.7 shows a partial implementation of the class, which includes the _ _init_ _, getMass, and _ _str_ _ methods. We leave development of the rest of the methods as an exercise.

Image

LISTING 10.7 Partial definition of the Sun class

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.30.236