- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverLoading.java
More file actions
Latest commit
65 lines (52 loc) · 1.78 KB
/
Copy pathMethodOverLoading.java
File metadata and controls
65 lines (52 loc) · 1.78 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
importjava.util.Scanner;
publicclassMethodOverLoading{
publicstaticvoidmain(String[] args){
Scannerinput = newScanner(System.in);
System.out.println("Calculate Perimeter of different shape");
System.out.println("Enter 1 to Calculate Perimeter of A Square");
System.out.println("Enter 2 to Calculate Perimeter of A Rectangle");
System.out.println("Enter 3 to Calculate Perimeter of A Circle");
System.out.println();
System.out.print("Enter your choice: ");
intchoice = input.nextInt();
switch(choice) {
case1:
{
System.out.print("Enter the length of the square: ");
intlengthOfSquare = input.nextInt();
MethodOverLoading.shape(LengthOfSquare);
}
break;
case2:
{
System.out.print("Enter the length of the rectangle: ");
intlengthOfRectangle = input.nextInt();
System.out.print("Enter the breadth of the rectangle: ");
intbreadthOfRectangle = input.nextInt();
MethodOverLoading.shape(LengthOfRectangle,breadthOfRectangle);
}
break;
case3:
{
System.out.print("Enter the radius of the circle: ");
doubleradiusOfCircle = input.nextInt();
MethodOverLoading.shape(raiduesOfCircle);
}
break;
default:
System.out.println("Invalid input");
}
}
publicstaticvoidshape(intlength){
intperimeterOfSquare = 4 * length;
System.out.printf("The perimter of Square is %d%n",perimterOfSquare);
}
publicstaticvoidshape(intlength, intbreadth) {
intperimeterOfRectangle = 2 * (length + breadth);
System.out.printf("The perimter of Rectangle is %d%n",perimeterOfRectangle);
}
publicstaticvoidshape(doubleradius){
intperimeterOfCircle = 2 * Math.PI * radiusOfCircle;
System.out.printf("The perimter Of Circle is %d%n",perimeterOfCircle);
}
}