Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1. A private variable of type

Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods:

1. A private variable of type double named radius to represent the radius. Set to 1.

2. Constructor Methods:

Python : An overloaded constructor method to create a default circle.

C# & Java: Default Constructor with no arguments.

C# & Java: Constructor method that creates a circle with user-specified radius.

3. Method getRadius() that returns the radius.

4. Method setRadius() that sets the radius.

5. Method getArea() that returns the area.

6. Method getCircumference() that returns the circumference.

7. Method To String,

Java: toString()

C#: ToString()

Python: __str__(self)

that prints out a meaningful description of the circle as follows:

The circle has radius X. Where X is the value of variable radius.

Now design and implement a test program to create a default circle object and test all class methods on the object. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.

Sample run:

Print radius:

The radius is 1.

Print area:

The area is 3.14

Print circumference:

The perimeter is 6.28

Set radius to 10 and print the object: The circle has radius 10.

Print area:

The area is 314.23

Print circumference:

The perimeter is 62.81

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions