Implement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: Circle.java, Cylinder.java. Do NOT include "public static void main()" method inside all of these classes. In this exercise, a subclass called Cylinder is derived from the superclass Circle as shown in the class diagram (where an arrow pointing up from the subclass to its superclass). Study how the subclass Cylinder invokes the superclass' constructors (via super() and super(radius)) and inherits the variables and methods from the superclass Circle. You can reuse the Circle class that you have created in the previous exercise. Make sure that you keep "Circle.class" in the same directory. Method Overriding and "Super": The subclass Cylinder inherits getArea() method from its superclass Circle. Try overriding the getArea() method in the subclass Cylinder to compute the surface area (=π×radius×radius×height) of the cylinder instead of the base area. That is, if getArea() is called by a Circle instance, it returns the area. If getArea() is called by a Cylinder instance, it returns the surface area of the cylinder. If you override the getArea() in the subclass Cylinder, the getVolume() no longer works. This is because the getVolume() uses the overridden getArea() method found in the same class. (Java runtime will search the superclass only if it cannot locate the method in this class). Fix the getVolume().

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implement all the classes using Java programming language from the given UML Class diagram.

Note: This problem requires you to submit just two classes: Circle.java, Cylinder.java.

Do NOT include "public static void main()" method inside all of these classes.

In this exercise, a subclass called Cylinder is derived from the superclass Circle as shown in the class diagram (where an arrow pointing up from the subclass to its superclass). Study how the subclass Cylinder invokes the superclass' constructors (via super() and super(radius)) and inherits the variables and methods from the superclass Circle.

You can reuse the Circle class that you have created in the previous exercise. Make sure that you keep "Circle.class" in the same directory.

Method Overriding and "Super": The subclass Cylinder inherits getArea() method from its superclass Circle. Try overriding the getArea() method in the subclass Cylinder to compute the surface area (=π×radius×radius×height) of the cylinder instead of the base area. That is, if getArea() is called by a Circle instance, it returns the area. If getArea() is called by a Cylinder instance, it returns the surface area of the cylinder.

If you override the getArea() in the subclass Cylinder, the getVolume() no longer works. This is because the getVolume() uses the overridden getArea() method found in the same class. (Java runtime will search the superclass only if it cannot locate the method in this class). Fix the getVolume().

Hints: After overriding the getArea() in subclass Cylinder, you can choose to invoke the getArea() of the superclass Circle by calling super.getArea().

TRY: Provide a toString() method to the Cylinder class, which overrides the toString() inherited from the superclass Circle, e.g.,

Try out the toString() method in TestCylinder.

Note: @Override is known as an annotation (introduced in JDK 1.5), which asks the compiler to check whether there is such a method in the superclass to be overridden. This helps greatly if you misspell the name of the toString(). If @Override is not used and toString() is misspelled as ToString(), it will be treated as a new method in the subclass, instead of overriding the superclass. If @Override is used, the compiler will signal an error. @Override annotation is optional but certainly nice to have.

Circle
-radius:double = 1.0
-color:String = "red"
%3D
+Circle()
+Circle(radius: double)
+Circle(radius:double,color:String)
+getRadius (): double
+setRadius (radius:double):void
+getColor():String
+setColor(color:String):void
+getArea(): double
+tostring():String.
"Circle[radius=r,color=c]"
superclass
subclass
extends
Cylinder
-height:double = 1.0
+Cylinder()
+Cylinder(radius:double)
+Cylinder(radius:double, height:double)
+Cylinder (radius:double, height:double,
color:String)
+getHeight():double
+setHeight (height:double):void
+getVolume (): double
Transcribed Image Text:Circle -radius:double = 1.0 -color:String = "red" %3D +Circle() +Circle(radius: double) +Circle(radius:double,color:String) +getRadius (): double +setRadius (radius:double):void +getColor():String +setColor(color:String):void +getArea(): double +tostring():String. "Circle[radius=r,color=c]" superclass subclass extends Cylinder -height:double = 1.0 +Cylinder() +Cylinder(radius:double) +Cylinder(radius:double, height:double) +Cylinder (radius:double, height:double, color:String) +getHeight():double +setHeight (height:double):void +getVolume (): double
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education