Question: Write a program that creates a class named Rectangle with the following details: Provide two ( 2 ) attributes: width and length.Provide an initialization method
Write a program that creates a class named Rectangle with the following details:
Provide two attributes: width and length.Provide an initialization method init to accept initial values for width and length attributes and only accept these parameters if they are not negative numbers.Provide methods getWidth and getLength to return the value of width and length.Provide methods setWidth and setLength that each accepts one parameter. Assign the parameter value to the class variable width or length if the value is not negative.Provide a method called FindPerimeter that takes no parameters. This method computes and returns the perimeter as widthlength.Provide the str method to convert the object myRect to a string consisting of width, length, and perimeter.
Create an object named myRect from class Rectangle with a width of and height of then:
Change the width of myRect to using the setWidth method.Use the getWidth and getLength methods of myRect to display the following messages:
Width of my rectangle is Length of my rectangle is
Print the following message on screen using the findPerimeter method of myRect:
Perimeter of my rectangle is x Note: when you run your code, x will be the number returned by the findPerimeter method.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
