ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2014 ICSE Computer Science Paper



Share with a Friend

Solved 2014 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Function Overloading - Area Program - ICSE 2014 Computer Science

Design a class to overload a function area() as follows:
(i) double area(double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
area = √(s(s – a)(s – b)(s – c))
where s = (a + b + c) / 2.

(ii) 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)

(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
area = 1/2 × (diagonal1 × diagonal2)

class Overload{ public static double area(double a, double b, double c){ double s = (a + b + c) / 2; return Math.sqrt(s * (s - a) * (s - b) * (s - c)); } public static double area(int a, int b, int height){ return 1.0 / 2 * height * (a + b); } public static double area(double diagonal1, double diagonal2){ return 1.0 / 2 * (diagonal1 * diagonal2); } }

Output