Hello everyone!
I'm a relatively newcommer to the programming experience, with a bit of knowledge in C++ and beginners Java.
I need help in an assignment of mine, which requires me to create a circle class and circle object, with a getradius method.
My teacher has provided a sample code:
public class Main
{
public static void main (String[] args)
{
// defines Circle object;
// call helper(class) method to input the radius
// instantiate the Circle object;
// output the circumference using instance method
// output the area using instance method
}
public static __________ getRadius()
{
// define a local radius variable
// read in a value for radius
// return the value
}
}
-----Circle.java--------------
public class Circle {
double radius;
public Circle(double rad)
{
radius = rad;
}
public double getRadius()
{
return radius;
}
public double getDiameter()
{
return 2.0*radius;
}
public double getCircumference()
{
return 2.0*Math.PI*radius;
}
public double getArea()
{
return Math.PI*radius*radius;
}
}
My question is:
1) the public class method is the actual circle object?
2) how do i define a circle object?
3) how do i instantiate the circle object?
4) and what are instance methods? How do I output results using an instance method?