-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodOverLoading.java
More file actions
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
import java.util.Scanner;
public class MethodOverLoading{
public static void main(String[] args){
Scanner input = new Scanner(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: ");
int choice = input.nextInt();
switch(choice) {
case 1:
{
System.out.print("Enter the length of the square: ");
int lengthOfSquare = input.nextInt();
MethodOverLoading.shape(LengthOfSquare);
}
break;
case 2:
{
System.out.print("Enter the length of the rectangle: ");
int lengthOfRectangle = input.nextInt();
System.out.print("Enter the breadth of the rectangle: ");
int breadthOfRectangle = input.nextInt();
MethodOverLoading.shape(LengthOfRectangle,breadthOfRectangle);
}
break;
case 3:
{
System.out.print("Enter the radius of the circle: ");
double radiusOfCircle = input.nextInt();
MethodOverLoading.shape(raiduesOfCircle);
}
break;
default:
System.out.println("Invalid input");
}
}
public static void shape(int length){
int perimeterOfSquare = 4 * length;
System.out.printf("The perimter of Square is %d%n",perimterOfSquare);
}
public static void shape(int length, int breadth) {
int perimeterOfRectangle = 2 * (length + breadth);
System.out.printf("The perimter of Rectangle is %d%n",perimeterOfRectangle);
}
public static void shape(double radius){
int perimeterOfCircle = 2 * Math.PI * radiusOfCircle;
System.out.printf("The perimter Of Circle is %d%n",perimeterOfCircle);
}
}