My Clone
2010-11-13 02:35:07 UTC
public class Circle
{
private double radius, area, perimeter;
static final double PI = 3.14;
public double getRadius()
{
return radius;
}
public double computeArea(double radius)
{
area = PI * radius * radius;
return area;
}
public double computePerimeter(double radius)
{
perimeter = 2 * PI * radius;
return perimeter;
}
public void printArea()
{
System.out.println("Area: " + area);
System.out.println();
}
public void printPerimeter()
{
System.out.println("Perimeter: " + perimeter);
System.out.println();
}
}
import java.util.Scanner;
public class Question1
{
public static void main(String[] args)
{
double radius, area;
int option = 0;
Scanner sc = new Scanner(System.in);
System.out.println("| 1. Create a new cirlce |");
System.out.println("| 2. Print area |");
System.out.println("| 3. Print circumference |");
System.out.println("| 4. Quit |");
System.out.println("==============================");
do {
System.out.print("Choose option (1-3): ");
option = sc.nextInt();
if (option == 1)
{
System.out.println("Enter the radius to compute the area and circuference: ");
radius = sc.nextDouble;
Circle.computeArea(radius);
Circle.computePerimeter(radius);
System.out.println("A new circle is created.");
}
else if (option == 2)
{
System.out.println("Area of circle");
System.out.println("Radius: " + getRadius);
Circle.printArea();
}
else if (option == 3)
{
System.out.println("Perimeter of circle");
System.out.println("Radius: " + getRadius);
Circle.printPerimeter();
}
else if (option == 4)
{
System.out.println("Invalid option!");
}
while (option != 7);
System.out.println("Thank you!!");
}
}
}
If someone can tell me why it is not compiling, I'd appreciate it a lot. Because it can't compile, I can't figure out if it works either. Please help, thanks!