-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArithmetic.java
More file actions
25 lines (21 loc) · 929 Bytes
/
Arithmetic.java
File metadata and controls
25 lines (21 loc) · 929 Bytes
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
import java.util.Scanner;
class Arithmetic{
protected float a;
protected float b;
Arithmetic(float a, float b){
this.a=a;
this.b=b;
}
float calc(){return 0;}
public static void main(String[] ar){
System.out.print("\nEnter first number: ");
float a=( new Scanner(System.in)).nextFloat();
System.out.print("\nEnter second number: ");
float b=( new Scanner(System.in)).nextFloat();
System.out.println(String.format("%1.1f+%1.1f=%2.2f",a,b,(new Add(a,b)).calc()));
System.out.println(String.format("%1.1f/%1.1f=%2.2f",a,b,(new Div(a,b)).calc()));
System.out.println(String.format("%1.1f*%1.1f=%2.2f",a,b,(new Mul(a,b)).calc()));
System.out.println(String.format("%1.1f-%1.1f=%2.2f",a,b,(new Sub(a,b)).calc()));
System.out.println(String.format("%1.1f(abstract)%1.1f=%2.2f",a,b,(new Arithmetic(9,8)).calc()));
}
}