I am hoping that the advantages of creating classes and objects start becoming obvious:

- it is clear in the final code that 3, 4, 5 are side values of a triangle

- the Triangle class defines how the triangle perimeter is calculated; this is done only once and then used by any of the objects of the class; imagine that the we need not one line of code for calculating the perimeter but 5 lines

- there is no code duplication any longer

I hope that this short example showed that programming can be learned and it is not as difficult as you may think.

How about some exercises using your new knowledge? :)

1. Create a rectangle class with methods for calculating the rectangle perimeter and area

2. Add a method to the Triangle class that checks if the triangle is scalene (all sides are different), isosceles (2 sides are equal) or equilateral (all sides are equal)?

If you liked this article and want to provide feedback or want to submit your solutions to the exercises, please use the comments section.