0

Design a class named Circle with fields

1. Design a class named Circle with fields named radius, area, and diameter. Include a constructor that sets the radius to 1. Include get methods for each field, but include a set method only for the radius. When the radius is set, do not allow it to be zero or a negative number. When the radius is set, calculate the diameter (twice the radius) and the area (the radius squared times pi, which is approximately 3.14). Create the class diagram and write the pseudocode that defines the class. I need help with This problem this is what I have so far but when I run it does not work it is in C++ code. // represents a circle public class Circle { private double radius, diameter, circumference, area; // constructor public Circle() { radius = 1; } // radius setter and getter public void setRadius(double radius) { this.radius = radius; } public double getRadius() { return radius; } // for diameter public double computeDiameter() { diameter = 2*radius; return diameter; } // for area public double computeArea() { area = 3.14*radius*radius; return area; } }

14th Nov 2019, 11:44 PM
LaRena
LaRena  - avatar
4 Réponses
+ 1
LaRena You have used "." instead of "->" for "this". Also you missed a ; at the end of the class. You do not mention the access modifier for each variable and method, like you have defined private and public in each line. You just type private: and write the variables below, similarly you write public: and write the methods below. These are some minor errors but you were almost there. You just had to create an instance of the class and call the set and get methods. This code is corrected. https://code.sololearn.com/cAxs4QG5xUbT/?ref=app
15th Nov 2019, 12:55 AM
Avinesh
Avinesh - avatar
+ 1
Thank you so much for your help Avinesh. 😁🙏🏻thank you
15th Nov 2019, 3:09 AM
LaRena
LaRena  - avatar
0
main not found
7th Apr 2021, 6:31 AM
Ann Marmie Bayeta
Ann Marmie Bayeta - avatar
0
can't run this program
7th Apr 2021, 6:31 AM
Ann Marmie Bayeta
Ann Marmie Bayeta - avatar