-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArea.java
More file actions
85 lines (56 loc) · 1.43 KB
/
Copy pathArea.java
File metadata and controls
85 lines (56 loc) · 1.43 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*Name ; Aljo Joby
* roll no. 08
* Batch : S3 CSE B
* Experiment : Finding area of shapes using method overloading
* Date: 11-10-2023
*/
package aljo;
import java.util.Scanner;
public class Area {
public static double Area(double side)
{
double area = side *side;
return area;
}
public static double Area(double length,double width)
{
double area = length * width;
return area;
}
public static double area(double radius)
{
double PI = 3.14;
double area = PI *radius*radius;
return area;
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Choose a shape");
String shape = sc.nextLine();
double result =0.0;
switch(shape)
{
case "square":
System.out.println("Enter the side of the square");
double side = sc.nextDouble();
result = Area(side);
break;
case "rectangle":
System.out.println("Enter the length and width of the rectangle");
double length = sc.nextDouble();
double width = sc.nextDouble();
result = Area(length,width);
break;
case "circle":
System.out.println("Enter the radius");
double radius = sc.nextDouble();
result = area(radius);
break;
default:
System.out.println("Error Occured");
}
sc.close();
System.out.println("the area of" +shape+"is" +result);
}
}