Construct a class named Circle with attributes named radius, diameter and area. Include a constructor that sets the radius to 1 and calculates the other two values. Include get and set methods for all the attributes. The setRadius() method not only sets the radius, it also calculates the other two values. The diameter of a circle is twice the radius and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Construct a class named Circle with attributes named radius, diameter and area. Include a constructor that sets the radius to 1 and calculates the other two values. Include get and set methods for all the attributes. The setRadius() method not only sets the radius, it also calculates the other two values. The diameter of a circle is twice the radius and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant for this calculation.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images