Upload files to "OOP/Java/Lab/Week8/RecCircleAbstract"

This commit is contained in:
Aadit Agrawal 2024-09-14 01:58:56 +05:30
parent ea71c33c38
commit 27ec687ff7

View File

@ -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();
}
}