Calculating areas of rectangles and circles

Report a typo

Create an abstract class called Shape with an abstract method area(). Implement two classes Rectangle and Circle that extend the Shape class and implement the area() method. Given the dimensions of a rectangle and a circle, calculate and print the area of each shape.

Sample Input 1:

5
3
4

Sample Output 1:

15.0
50.26548245743669

Sample Input 2:

10
8
6

Sample Output 2:

80.0
113.09733552923255
Write a program in Java 25
import java.util.Scanner;

// Define the abstract Shape class with an abstract area() method

// Implement the Rectangle class that extends Shape

// Implement the Circle class that extends Shape

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Read the dimensions of the rectangle
double length = scanner.nextDouble();
double width = scanner.nextDouble();

// Read the radius of the circle
double radius = scanner.nextDouble();

// Create instances of Rectangle and Circle

// Calculate and print the area of the rectangle

// Calculate and print the area of the circle

scanner.close();
}
}

Create a free account to access the full topic