import java.util.*;
import java.math.RoundingMode;  
import java.text.DecimalFormat;  
class shape{
    protected double area;
    public double getarea(){
        return area;
    }
    public void setarea(double finalarea){
        area=finalarea;
    }
    public void computearea(){
        area=0;
    }
    
}
class circle extends shape{
    private double radius;
    public double getradius(){
        return radius;
    }
    public void setradius(double newradius){
        radius=newradius;
    }
    public void computearea(){
        area=(3.14)*(radius*radius);
        setarea(area);
    }
}
class rectangle extends shape{
    private double leng;
    private double breadth;
    public double getleng(){
        return leng;
    }
    public void setleng(double newleng){
        leng=newleng;
    }
    public double getbreadth(){
        return breadth;
    }
    public void setbreadth(double newbreadth){
        breadth=newbreadth;
    }
    public void computearea(){
        area=(leng*breadth);
        setarea(area);
    }
}
class triangle extends shape{
    private double base;
    private double height;
    public double getbase(){
        return base;
    }
    public void setbase(double newbase){
        base=newbase;
    }
    public double getheight(){
        return height;
    }
    public void setheight(double newheight){
        height=newheight;
    }
    public void computearea(){
        area=(1/2d)*(base*height);
        setarea(area);
    }
}
public class Main{
    public static final DecimalFormat decfor = new DecimalFormat("0.00");
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
          
        int type=sc.nextInt();
        sc.nextLine();
        if (type==1){
            double k=sc.nextDouble();
            circle obj=new circle();
            obj.setradius(k);
            obj.computearea();
            System.out.println(decfor.format(obj.getarea()));
        }
        else if(type==2){
            double l=sc.nextDouble();
            sc.nextLine();
            double b=sc.nextDouble();
            rectangle obj=new rectangle();
            obj.setleng(l);
            obj.setbreadth(b);
            obj.computearea();
            System.out.println(decfor.format(obj.getarea())); 
        }
        else{
            double ba=sc.nextDouble();
            double h=sc.nextDouble();
            triangle obj=new triangle();
            obj.setbase(ba);
            obj.setheight(h);
            obj.computearea();
            System.out.println(decfor.format(obj.getarea()));
            
        }
        
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: