Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The oval subclass does not want to provide either the SetAngle1 or SetAngle2 methods because it is a closed arc. The circle subclass additionally wants

image text in transcribed

The oval subclass does not want to provide either the SetAngle1 or SetAngle2 methods because it is a closed arc. The circle subclass additionally wants to eliminate the setWidth and setHeight methods and add a setDiameter method. Answer the following questions:

  1. What is the problem with the class hierarchy?
  2. Suggest another way to implement the oval and circle subclasses that allows you to "inherit" the implementation of the arc subclass without incurring the disadvantages of actual inheritance. Sketch out a sample Java class declaration for a circle that includes the following elements:
    1. declarations for the instance variable(s)
    2. declarations for the public methods (it is okay to use my "some parameters" notation for the parameters to the Draw method)
    3. implementations for the setLeft and setDiameter methods.
6. The type of graphics commands provided by a graphics package can influence the way a class hierarchy is designed. For example, some graphics systems, including X, provide a single command for drawing arcs, ovals, and circles. More particularly, X's command for drawing arcs, ovals, and circles can be roughly written as follows: DrawArc(left, top, width, height, anglel, angle2) anglel and anglez denote the beginning and ending angle of the arc. An oval can be created by setting anglel to 0 and angle2 to 360. A circle can be similarly created, except that in addition the width must equal the height. The format of this command could lead you to define a class hierarchy in which an oval is a subclass of an arc, and a circle is a subclass of an oval: arc oval circle The arc class might define the following methods: a. void SetAnglel(double angle); b. void SetAngle2(double angle); c. void Draw(some parameters); d. void setLeft(int left); e. void setTop(int top); f. void setWidth(int width); g. void setHeight(int height); 6. The type of graphics commands provided by a graphics package can influence the way a class hierarchy is designed. For example, some graphics systems, including X, provide a single command for drawing arcs, ovals, and circles. More particularly, X's command for drawing arcs, ovals, and circles can be roughly written as follows: DrawArc(left, top, width, height, anglel, angle2) anglel and anglez denote the beginning and ending angle of the arc. An oval can be created by setting anglel to 0 and angle2 to 360. A circle can be similarly created, except that in addition the width must equal the height. The format of this command could lead you to define a class hierarchy in which an oval is a subclass of an arc, and a circle is a subclass of an oval: arc oval circle The arc class might define the following methods: a. void SetAnglel(double angle); b. void SetAngle2(double angle); c. void Draw(some parameters); d. void setLeft(int left); e. void setTop(int top); f. void setWidth(int width); g. void setHeight(int height)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago