42 lines
		
	
	
	
		
			843 B
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			843 B
		
	
	
	
		
			Java
		
	
	
	
	
	
interface Shape {
 | 
						|
    double calculateArea();
 | 
						|
}
 | 
						|
 | 
						|
class Square implements Shape {
 | 
						|
 | 
						|
    private double side;
 | 
						|
 | 
						|
    public Square(double side) {
 | 
						|
        this.side = side;
 | 
						|
    }
 | 
						|
 | 
						|
    public double calculateArea() {
 | 
						|
        return side * side;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
class Triangle implements Shape {
 | 
						|
 | 
						|
    private double base;
 | 
						|
    private double height;
 | 
						|
 | 
						|
    public Triangle(double base, double height) {
 | 
						|
        this.base = base;
 | 
						|
        this.height = height;
 | 
						|
    }
 | 
						|
 | 
						|
    public double calculateArea() {
 | 
						|
        return 0.5 * base * height;
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
public class Main {
 | 
						|
 | 
						|
    public static void main(String[] args) {
 | 
						|
        Shape square = new Square(5.0);
 | 
						|
        Shape triangle = new Triangle(4.0, 6.0);
 | 
						|
 | 
						|
        System.out.println("Area of Square: " + square.calculateArea());
 | 
						|
        System.out.println("Area of Triangle: " + triangle.calculateArea());
 | 
						|
    }
 | 
						|
}
 |