diff --git a/OOP/Java/Lab/Week8/RecCircleAbstract/RecCircleAbstract.java b/OOP/Java/Lab/Week8/RecCircleAbstract/RecCircleAbstract.java new file mode 100644 index 0000000..873e1db --- /dev/null +++ b/OOP/Java/Lab/Week8/RecCircleAbstract/RecCircleAbstract.java @@ -0,0 +1,57 @@ +import java.util.Scanner; + +abstract class Shape { + + abstract double calculateArea(); +} + +class Rectangle extends Shape { + + double length; + double width; + + Rectangle(double length, double width) { + this.length = length; + this.width = width; + } + + double calculateArea() { + return length * width; + } +} + +class Circle extends Shape { + + double radius; + + Circle(double radius) { + this.radius = radius; + } + + double calculateArea() { + return Math.PI * radius * radius; + } +} + +class RecCircleAbstract { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter rectangle length: "); + double length = scanner.nextDouble(); + System.out.print("Enter rectangle width: "); + double width = scanner.nextDouble(); + + Rectangle rectangle = new Rectangle(length, width); + System.out.println("Rectangle area: " + rectangle.calculateArea()); + + System.out.print("Enter circle radius: "); + double radius = scanner.nextDouble(); + + Circle circle = new Circle(radius); + System.out.println("Circle area: " + circle.calculateArea()); + + scanner.close(); + } +}