Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Qn 4) Using Python Programming Language only, write a Shape, a Circle, a Rectangle and a Square classes with the following requirements: Shape class: -

Qn 4) Using Python Programming Language only, write a Shape, a Circle, a Rectangle and a Square classes with the following requirements: Shape class: - has 2 private variables filled (boolean) & colour (string) - the filled & colour properties are set during initialization, if nothing is given, filled & colour defaults to True and 'Green' respectively - accessor methods for both variables - the Shape class must return a string representation following the format 'Shape[colour=, filled=]' when called from the print() function

Circle class: - is derived from the Shape class - has 1 additional private variable radius - its properties are set during initialization, if nothing is given, radius defaults to 1.0. - accessor methods for the radius variable - the Circle class must know how to calculate its own area and perimeter - the Circle class must return a string representation following the format 'Circle[Shape[filled=, colour=], radius=]' when called from the print() function - round all numbers to 2 decimal places

Rectangle class: - is derived from the Shape class - has 2 additional private variable width & length - its properties are set during initialization, if nothing is given, both width & length defaults to 1.0. - accessor methods for both the width & length variable - the Rectangle class must know how to calculate its own area and perimeter - the Circle class must return a string representation following the format 'Rectangle[Shape[filled=, colour=], width=, length=]' when called from the print() function - round all numbers to 2 decimal places

Square class: - is derived from the Rectangle class - has 1 additional private variable side - its properties are set during initialization, if nothing is given, side defaults to 1.0. - accessor methods for the side (Note that the accessor methods should set both the width & length of the parent class and get the value of either width or length from the parent class) - the Square class must return a string representation following the format 'Square[Rectangle[Shape[filled=, colour=], width=, length=]]' when called from the print() function - round all numbers to 2 decimal places

Sample Program Output: Circle[Shape[colour=Green, filled=True], radius=5] area=78.54 perimeter=31.42 Square[Rectangle[Shape[colour=Green, filled=True], width=5, length=5]] area=25 perimeter=20

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago

Question

2. The model is credible to the trainees.

Answered: 1 week ago