Okay so my teacher assigned us this to do and I am going through it. I am very c
ID: 3553519 • Letter: O
Question
Okay so my teacher assigned us this to do and I am going through it. I am very confused with this whole thing. We went over classes once and will probably go over it again but I still need help.
I just need someone to do the first method that I have below. I dont understand why HE (the teacher) put down private final double PI= 3.14. I googled how to do classes and not one of them has done anything with private as opposed to public. I know what private and public mean but the class is public and the double is private which really confuses me. PLEASE HELP ME!
public class MyCircle { //Define the constant PI. private final double PI = 3.141592; //The MyCircle class has one property: radius //Put a radius in your class //The MyCircle class has methods too. //Make a method that calculates the diameter of a circle. Recall the radius is half of the diameter. //This method will take no parameters and return a double. //Why no parameters? Because the circle class has a radius built in. All methods in the Circle class have access to it without it being passed //as a parameter! Sweet! Explanation / Answer
Dear,
Here is the implementation of class as per requirements:
public class MyCircle
{
//Define the constant PI.
private final double PI = 3.141592;
private double radius;
public MyCircle(double r)
{
radius= r;
}
public double getDiameter()
{
return radius/2;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.