-
Notifications
You must be signed in to change notification settings - Fork 0
/
practical12.java
60 lines (60 loc) · 1.9 KB
/
practical12.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
import java.util.Scanner;
public class practical12 {
public static class first{
void add(int a, int b){
System.out.println("the addition of "+a+" and "+b+" is "+(a+b));
}
}
public static class second extends first{
void sub(int a, int b){
System.out.println("the subtraction of "+a+" and "+b+" is "+(a-b));
}
}
public static class third extends second{
void mul(int a, int b){
System.out.println("the multiplication of "+a+" and "+b+" is "+(a*b));
}
}
public static class fourth extends third{
void div(int a, int b){
float c;
c = (float) a /b;
System.out.println("the subtraction of "+a+" and "+b+" is "+c);
}
}
public static void main(String[] args){
System.out.println("Program for simple calculator");
Scanner sc = new Scanner(System.in);
fourth obj = new fourth();
int a,b;
int c;
System.out.print("Enter first no :");
a = sc.nextInt();
System.out.print("Enter second no :");
b = sc.nextInt();
System.out.println("Enter the operator to perform between them :");
System.out.println("for addition press 1");
System.out.println("for subtraction press 2");
System.out.println("for multiplication press 3");
System.out.println("for division press 4");
System.out.print("enter the no: ");
c = sc.nextInt();
System.out.println();
switch (c){
case 1 :
obj.add(a,b);
break;
case 2 :
obj.sub(a,b);
break;
case 3 :
obj.mul(a,b);
break;
case 4 :
obj.div(a,b);
break;
default:
System.out.println("Enter valid input!!");
}
}
}