Question
Input The first input will be radius then followed by length and width at next line. Output CircleRectanglecalArea() Examples 5 input 46 output 78.50
Input The first input will be radius then followed by length and width at next line. Output CircleRectanglecalArea() Examples 5 input 46 output 78.50 24.00 Please declare a abstract class Shape, having the abstract method calArea() to compute the area of the shape. Two classes Rectangle and Circle are derived from Shape. Class Rectangle has float data field length and width. Class Circle has float data field radius. The main class is given as shown in Preset code. (Preset code) import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner in = new Scanner(System.in); double radius, length, width; radius = in.nextDouble(); Shape circle = new Circle(radius); System.out.println(String.format("%.2f",circle.calArea())); length = in.nextDouble(); width = in.nextDouble(); Shape rectangle = new Rectangle(length, width); System.out.println(String.format("%.2f", rectangle.calArea())); } } abstract class Shape{ public abstract double calArea(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started