Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics: class, method, object instantiation, inheritance, print Problem Statement: In this assignment, you will design one child class 'MountainBike' of a parent class 'Bicycle'. The

image text in transcribed

image text in transcribed

image text in transcribed

Topics: class, method, object instantiation, inheritance, print Problem Statement: In this assignment, you will design one child class 'MountainBike' of a parent class 'Bicycle'. The purpose of this lab is to gain experience in python's basic inheritance lass Definition: Bicycle Class (Parent class This class will have following instance variables and methods. Most Definition is provided in the template file. Attribute name/Instance varibales gear speed Data type Description int float Gear number includes 1-3 Speed of the cycle in mile per hour Method name Parameter gear, speed decrement Return type Description Initialize the instance attributes Decrease the speed by 'decrement variable init none applyBrake none Increase the speed by increment variable speedUp increment none Your Task: Design a MountainBike Class (Child class) with the following instance variables and methods Attribute name/Instance variables gear speed seatHeight Data type int float float Description Gear number includes 1-3 Speed of the cycle in mile per hour Height of the seat in cm Method name Parameter gear, speed, seatHeight none Return type none string Description Initialize the instance attributes Returns the current information of object. See sample lI/O Set the seatHeight to 'newValue' init str setHeight newValue none Object Creation/Instantiation: You need to create two objects m1' and 'm2' of 'MountainBike, class. Sample code has been provided in the template file. Sample output Object m1 No of gear: 3 Current speed: 10 Current seat height: 100 Object m2 No of gear: 2 Current speed: 5 Current seat height: 90 No of gear: 2 Current speed: 5 Current seat height: 76 class Bicycle (object): #parent class def _init__(self, gear, speed): self.geargear self. speed = speed def applyBrake (self, decrement): self.speed -decrement def speedUp (self, increment): #your code here #same as applyBrake #increase the speed by increment class MountainBike (Bicycle): def _init__(self, gear, speed, seatHeight): #your code here #super() call to invoke parents init method- gear and speed com #initialize seatHelght - an added attribute of child class def setHeight (self, newvalue): #an added meth d of child class #your code here #set the seatHelght to newvalue def-str-(self): #a method to print object for child #your code here #return a string #see sample I/O #object creation m1MountainBike (3, 10, 100) m2MountainBike (2, 5, 90) print (m1) print (m2) m2.setHeight (76) #reset the value of seatHeight print (m2)

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

What is a Contract Data Requirements List (CDRL)?

Answered: 1 week ago

Question

Write short notes on Interviews.

Answered: 1 week ago