Write a class called Circle that contains: a. Three private attributes: radius (of the type double), color (of the type
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Write a class called Circle that contains: a. Three private attributes: radius (of the type double), color (of the type
Write a class called Circle that contains: a. Three privateattributes: radius (of the type double), color (of the typeString), and area (of type double). b. Two constructors - a defaultconstructor with no argument (default value of radius is 2.0, andcolor is Green) and a parameterized constructor, which initializesonly the radius and the color variables. c. Getter and setter forthe radius and color variables. d. Two public methods:calculateArea(), and getPerimeter, which return the area andperimeter of a circle instance, respectively. Both methods havereturn statements. Then write a driver class that tests the Circleclass. In the driver class, create two objects of Circle class, onethat tests the default constructor of the Circle class (here nouser input is required) and then get the color, radius, area, andperimeter of that object and display them. The second object shouldtest the parameterized constructor (here you need to ask the userto give you input to initialize the class variables). The codeshould ensure that the radius given by the user is positive. If theradius is not positive, the code will keep asking the user toreenter a value. Once the radius is positive, the code should getthe color, radius, area, and perimeter of that object accordinglyand display them. Then you need to ask the user again to give you anew radius for the second object of the class Circle. Again, thecode should ensure that the new radius given by the user ispositive. If the radius is not positive, the code will keep askingthe user to reenter a value. Then you need to read the new radiusand calculate the new area and perimeter accordingly and displaythem.