Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

class Circle { private double radius; // Radius of this circle f nal double PI =

ID: 659508 • Letter: C

Question

class Circle

{

private double radius; // Radius of this circle

f nal double PI = 3.14159;

public void setRadius(double rad)

{

radius = rad;

}

public double getRadius()

{

return radius;

}

public double calculateCircumference()

{

return (2 * PI * radius);

}

public double calculateArea()

{

return(PI * radius * radius);

}

} // End of Circle class

In this exercise, assume that a Circle object named oneCircle has

been created in a program that uses the Circle class, and radius is

given a value as shown in the following code:

Circle Circle();

oneCircle.setRadius(4.5);

1. What is the output when the following line of Java code executes?

System.out.println("The circumference is : " +

oneCircle.calculateCircumference());

2. Is the following a legal Java statement? Why or why not?

System.out.println("The area is : " + calculateArea());

3. Consider the following Java code. What is the value stored in the oneCircle object

Explanation / Answer

class Circle
{
private double radius; // Radius of this circle
f nal double PI = 3.14159;
public void setRadius(double rad)
{
radius = rad;
}
public double getRadius()
{
return radius;
}
public double calculateCircumference()
{
return (2 * PI * radius);
}
public double calculateArea()
{
return(PI * radius * radius);
}
} // End of Circle class

Circle Circle();
oneCircle.setRadius(4.5);
1. What is the output when the following line of Java code executes?
System.out.println("The circumference is : " + oneCircle.calculateCircumference());
The circumference is : 28.27431
2. Is the following a legal Java statement? Why or why not?
System.out.println("The area is : " + calculateArea());
// this statement is not valid as calculateArea() has to be called on object.
3. Consider the following Java code. What is the value stored in the oneCircle object