12.6 Exercises


12.6 Exercises

  1. Explain the difference between horizontal and vertical relationships. How can these be illustrated in UML diagrams?

  2. In what way does inheritance enhance class reuse? Why is this important?

  3. Because attributes are private in KJP, explain the limitations in dealing with inheritance.

  4. One of the examples discussed in this chapter is class Toyball as a subclass of class Ball. Draw UML diagrams, and design and write a complete KJP program for a sport using specialized objects of class Ball. Choose tennis or volleyball (or any other sport of your preference).

  5. Repeat the previous problem with the subclass being a specialization and an extension of the base class.

  6. Draw the corresponding UML diagrams, redesign, and rewrite class Manager for the salary problem. Provide a class that includes function main and that creates and manipulates objects of class Manager and objects of class Employeec. Class Manager should be an extension and a specialization of class Employeec. Explain how class reuse is being applied in this problem.

  7. Refer to Figure 12.1. Design and write the class definitions for the four classes. Class Polygon is the base class, the most simple and general class in the hierarchy. The other three classes are specializations and/or extensions of the base class. These three classes should provide functions to compute the perimeter and the area for the corresponding objects.

  8. How would you include classes Circle and Sphere in the class hierarchy of the previous problem? Write the KJP program with the class implementations for these two classes.

  9. A complex number has two attributes, the real part and the imaginary part. The two basic operations on complex numbers are complex addition and complex subtraction. Design and implement a KJP program for simple complex numbers. A slightly more advanced pair of operations are complex multiplication and complex division. Design and write the KJP program that includes an extension to the basic complex numbers. Hint: in addition to the rectangular representation of complex numbers (x,y), it might be useful to include attributes for the polar representation of complex numbers (module, angle).

  10. Consider a class hierarchy involving motor vehicles. At the top of the hierarchy, class Motor_vehicle represents the most basic and general type of vehicles. Automobiles, Trucks, and Motorcycles are three types of vehicles that are extensions and specializations of the base class. Sport_automobiles are included in the class hierarchy as a subclass of Automobile. Design and implement a KJP program with all these classes. Include attributes such as horse power, maximum speed, passenger capacity, load capacity, and weight. Include the relevant functions.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net