Class 10th ICSE

Q.1

1. Design a class to overload a function area() as follows:
(a) double area(double a, double b, double c)-with three double arguments,
returns the area of a scalene triangle using the formula:
area=√𝐬(𝐬 βˆ’ 𝐚)(𝐬 βˆ’ 𝐛)(𝐬 βˆ’ 𝐜) where s=(a+b+c)/2
(b) double area(int a, int b, int height)-with three integer arguments, returns
the area of a trapezium using the formula:
area=1/2*height(a +b)
(c) double area(double diagonal1,double diagonal2)-with two double
arguments, returns the area of a rhombus using the formula:
area=1/2*diagonal1*diagonal2

Solution :-Β 

import java.util.*;
class p1{
double area(double a,double b,double c){
double s=(a+b+c)/2;
double d=s*((s-a)(s-b)(s-c));
double area1=(Math.sqrt(s*((s-a)(s-b)(s-c))));
return area1;
}
double area(int a,int b,int height){
double area2=0.5*height*(a+b);
return area2;
}
double area(double diagonal1,double diagonal2){
double area3=0.5*diagonal1*diagonal2;
return area3;
}
public static void main(){
overloading obj=new overloading();
double res1=obj.area(2.0,4.0,4.0);
double res2=obj.area(3,4,5);
double res3=obj.area(6.0,8.0);
System.out.println(β€œArea of scalene triangle=”+res1);
System.out.println(β€œArea of trapezium=”+res2);
System.out.println(β€œArea of rhombus =”+res3);
}
}

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable