-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverloader.java
More file actions
60 lines (57 loc) · 1.44 KB
/
overloader.java
File metadata and controls
60 lines (57 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package Lab;
import java.util.Scanner;
class Areas
{
public void area(double r)
{
double area=3.14*Math.pow(r, 2) ;
System.out.println("Area of circle is "+area);
}
public void area(double l,double b)
{
double area=l*b;
System.out.println("Area of Rectangle is "+area);
}
public void area(double a,double b ,double c)
{ double s=(a+b+c)/2.0;
double area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
System.out.println("Area of triangle is "+area);
}
}
public class overloader {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
Areas a=new Areas();
while(true)
{ System.out.println();
System.out.println("THE MENU IS AS FOLLOWS");
System.out.println();
System.out.println("1.AREA OF CIRCLE");
System.out.println("2.AREA OF RECTANGLE");
System.out.println("3.AREA OF TRIANGLE");
System.out.println("4.EXIT");
System.out.println();
System.out.println("Enter your choice");
int op=sc.nextInt();
switch(op)
{
case 1: System.out.println("Enter the radius");
double radius=sc.nextDouble();
a.area(radius);
break;
case 2: System.out.println("Enter the length and breadth");
double l=sc.nextDouble();
double b=sc.nextDouble();
a.area(l, b);
break;
case 3: System.out.println("Enter the 3 sides ");
double x=sc.nextDouble();
double y=sc.nextDouble();
double z=sc.nextDouble();
a.area(x,y,z);
break;
case 4: System.out.println("EXITING....");
System.exit(0);
}
}}}