// Input 1 required value and then calculate and display
// the inputted value, perimeter and area of a circle.
import java.awt.*;
import hsa.Console;
public class Circle
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
double radius;
double diameter;
final double PI = 3.14159;
double perimeter;
double area;
c.print ("Enter the value of the radius of the circle: ");
radius = c.readDouble ();
diameter = 2 * radius;
// display the inputted value (radius) and the calculated value
// of diameter (2 * radius)
c.println ("You just inputted the value of a radius of " + radius
+ " cm");
c.println ("The diameter is calculated as twice the radius = "
+ diameter + " cm");
// first, calculate the perimeter of the circle
// using the formula: perimeter = 2 * PI * radius OR
// PI * diameter
perimeter = 2 * PI * radius;
// final output statement # 1
c.println (); // one blank line
c.println ("The perimeter of the circle with a radius of " + radius
+ " is about: " + Math.round (perimeter) + " cm");
// next, calculate the area of the circle
// using the formula: area = PI * (radius * radius) OR
// PI * Math.pow (radius,2)
area = PI * Math.pow (radius, 2);
// final output statement # 2
c.println ();
c.println ("The area of the circle with a radius of " + radius
+ " is about: " + Math.round (area) + " cm squared");
} // main method
} // Circle class
No comments:
Post a Comment