-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractiseoverloading.java
More file actions
138 lines (133 loc) · 4.16 KB
/
Copy pathpractiseoverloading.java
File metadata and controls
138 lines (133 loc) · 4.16 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.util.*;
public class practiseoverloading
{
static void square()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the number:");
int b=s.nextInt();
float a=b*b;
System.out.println("the area of square is:"+a);
}
static void rectangle()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the length:");
int l=s.nextInt();
System.out.println("enter the breadth:");
int b=s.nextInt();
float a=l*b;
System.out.println("the area of rectangle is:"+a);
}
static void triangle()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the base:");
int b=s.nextInt();
System.out.println("enter the height:");
int h=s.nextInt();
float a=(b*h)/2;
System.out.println("the area of rectangle is:"+a);
}
static void square()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the number:");
int s=s.nextInt();
float p=4*s;
System.out.println("the perimeter of square is:"+p);
}
static void rectangle()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the length:");
int l=s.nextInt();
System.out.println("enter the breadth:");
int b=s.nextInt();
float p=4*(l*b);
System.out.println("the perimeter of rectangle is:"+p);
}
static void triangle()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the first side:");
int a=s.nextInt();
System.out.println("enter the second side:");
int b=s.nextInt();
System.out.println("enter the third side:");
int c=s.nextInt();
float p=a+b+c;;
System.out.println("the perimeter of triangle is:"+p);
}
static void square()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the side:");
int n=s.nextInt();
float a=n*n;
System.out.println("the square of "+n+" is" +a);
}
static void squareroot()
{
Scanner s=new Scanner(System.in);
System.out.println("enter the number:");
int n=s.nextInt();
double a= Math.sqrt(n);
System.out.println("the squareroot of "+n+" is "+a);
}
public static void main(String[] args)
{
Scanner s= new Scanner(System.in);
System.out.println("Enter your choice:");
System.out.println("1.Area\n2.Perimeter\n3.Square\n4.Squareroot");
int ch=s.nextInt();
switch(ch)
{
case 1:
area ab=new area();
System.out.println("enter your choice:\n");
System.out.println("1.square\n 2. rectangle\n 3.triangle\n");
int ay=s.nextInt();
switch(ay)
{
case 1:
ab.square();
case 2:
ab.rectangle();
break;
case 3:
ab.triangle();
break;
default:System.out.println("!!Invalid Choice Try Again!!");
}
break;
case 2:
perimeter abh=new perimeter();
System.out.println("enter your choice:\n");
System.out.println("1.square\n 2. rectangle\n 3.triangle\n");
int hm=s.nextInt();
switch(hm)
{
case 1:
abh.square();
break;
case 2:
abh.rectangle();
break;
case 3:
abh.triangle();
default: System.out.println("!!Invalid Choice Try Again!!");
}
break;
case 3:
square ayu= new square();
ayu.square();
break;
case 4:
squareroot zx=new squareroot();
zx.squareroot();
break;
default: System.out.println("!!Invalid Choice Try Again!!");
}
}
}