Question
Creating simple classes and instantiating objects. Including attributes and methods to classes. In the blank trinket given, define an empty class named Circle and instantiate
Creating simple classes and instantiating objects. Including attributes and methods to classes.
In the blank trinket given, define an empty class named Circle and instantiate an object of this class.
Include a method named setRadius() to set the attribute radius of Circle. Call this method for the object created in (i).
Include methods to calculate area and perimeter of circle. Call these methods for objects created in (i).
Inheritance. In this activity, we will create a parent class MediaFile and two subclasses, MusicFile and VideoFile, that are related to MediaFile by single inheritance.
In the blank trinket file, create a class MediaFile that has two attributes: title and duration. It has three methods: setTitle, setDuration and play(). Methods setTitle() and setDuration() are used to set the attributes title and duration respectively. The play() method prints a statement in the form: playing file
In the same trinket file, create class MusicFile using its parent class, MediaFile. Class MusicFile also consists of attribute artist that stores the name of the artist. Include a method setArtist() to set attribute artist. play() method of this class prints: playing song
In the same trinket file, create class VideoFile using its parent class, MediaFile. Class VideoFile also consists of attribute quality that stores the name of the picture quality (SD, HD, etc). Include a method setQuality() to set attribute quality. play() method of this class prints: playing video
Instantiate a MusicFile object. Set appropriate values using its methods and call the play() method.
Instantiate a VideoFile object. Set appropriate values using its methods and call the play() method.
Using super() method.
The given code defines classes rectangle and square. Square inherits a few properties of rectangles. Instantiate a Square object and use the calArea() and calPerimter() methods to display the area and perimeter of the object.
class Rectangle:
def set(self, length, breadth):
self.length=length
self.breadth=breadth
def calArea(self):
return self.length*self.breadth
def calPerimeter(self):
return 2*(self.length+self.breadth)
class Square(Rectangle):
def set(self, side):
super().set(side, side)
The surface area of the cube is equal to 6 times its face area. Face area is the area of the square. Create class Cube by inheriting Square class. Within the class, create a method to calculate the surface area of a cube. Implement super() method in your method.
The volume of a cube can be stated as the face area times the side of a cube. Within the class definition of Cube, include a method to calculate volume of a cube. Implement super() function in your method.
Instantiate a Cube object and write statements to print its surface area and volume.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started