From 27ec687ff7536617feecfc64aa17ecd5c47403bc Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 14 Sep 2024 01:58:56 +0530 Subject: [PATCH] Upload files to "OOP/Java/Lab/Week8/RecCircleAbstract" --- .../RecCircleAbstract/RecCircleAbstract.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 OOP/Java/Lab/Week8/RecCircleAbstract/RecCircleAbstract.java 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(); + } +}