Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Challenge 1: Implement Rectangle Class Using the Encapsulation

Sumit Rawal answered on May 17, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Solution Review: Implement the Rectangle Class Using the Concepts of Encapsulation

  • Challenge 1: Implement Rectangle Class Using the Encapsulation

    0

    Problem statement

    You are given a partially completed code of a Rectangle class in the editor. Implement the class by completing the tasks below.

    Task 1

    Implement a constructor to initialize the values of two private properties: length and width.

    Task 2

    Implement a method, area(), in the Rectangle class that returns the product of length and width. See the formula below:

    Area=length×width

    Sample properties

    length = 4

    width = 5

    Sample method output

    20

    Task 3

    Implement a method, perimeter(), in the Rectangle class that returns two times the sum of length and width. See the formula below:

    Perimeter=2×(length+width)

    Sample properties

    length = 4

    width = 5

    Sample method output

    18

    Coding exercise

    First, take a close, and then design a step-by-step algorithm before trying the implementation. This problem is designed for your practice, so initially try to solve it on your own. If you get stuck, you can always refer to the solution provided in the next lesson. 

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 17 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.