package Exam;

import java.util.Scanner;

//추상 클래스
abstract class Shape {
	abstract double calculateArea(); // 추상 메서드
}

//원 클래스
class Circle extends Shape {
	double radius;

	Circle(double radius) {
		this.radius = radius;
	}

	@Override
	double calculateArea() {
		return Math.PI * radius * radius;
	}
}

//사각형 클래스
class Rectangle extends Shape {
	double width, height;

	Rectangle(double width, double height) {
		this.width = width;
		this.height = height;
	}

	@Override
	double calculateArea() {
		return width * height;
	}
}

//실행 클래스
public class C7_Pro01_ShapeTest {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		System.out.print("도형 선택(1. 원, 2. 사각형): ");
		int choice = sc.nextInt();

		Shape shape;

		if (choice == 1) {
			System.out.print("반지름 입력: ");
			double r = sc.nextDouble();
			shape = new Circle(r);
		} else {
			System.out.print("가로 입력: ");
			double w = sc.nextDouble();
			System.out.print("세로 입력: ");
			double h = sc.nextDouble();
			shape = new Rectangle(w, h);
		}

		System.out.println("도형의 넓이: " + shape.calculateArea());
		sc.close();
	}
}
