-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface4.java
77 lines (69 loc) · 1.91 KB
/
interface4.java
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
import java.util.Scanner;
interface add
{
public void addition(int a,int b);
}
interface sub
{
public void subtraction(int a,int b);
}
interface mul
{
public void multiplication(int a,int b);
}
interface div extends add,sub,mul
{
public void division(int a,int b);
}
class calc implements div{
public void addition(int a,int b)
{
int c = a+b;
System.out.println("the sum is = "+c);
}
public void subtraction(int a ,int b)
{
int c = a-b;
System.out.println("the subtraction is = "+c);
}
public void multiplication(int a,int b)
{
int c = a*b;
System.out.println("the multiplication is = "+c);
}
public void division(int a,int b)
{
int c = a/b;
System.out.println("the division is = "+c);
}
}
public class interface4{
public static void main(String[] args) {
int a,b;
int ch;
calc obj = new calc();
Scanner sc = new Scanner(System.in);
System.out.println("enter the value of a = ");
a = sc.nextInt();
System.out.println("enter the value of b = ");
b = sc.nextInt();
System.out.println("----enter the below operation to perform any operation------");
System.out.println("press 1 for addition");
System.out.println("press 2 for subtraction");
System.out.println("press 3 for multiplication");
System.out.println("press 4 for division");
ch = sc.nextInt();
switch(ch)
{
case 1 : obj.addition(a,b);
break;
case 2 : obj.subtraction(a,b);
break;
case 3 : obj.multiplication(a,b);
break;
case 4 : obj.division(a,b);
break;
default : System.out.println("enter a valid choice"); break;
}
}
}