-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperacoes.java
More file actions
57 lines (56 loc) · 1.43 KB
/
Copy pathOperacoes.java
File metadata and controls
57 lines (56 loc) · 1.43 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
package br.com.bb.Calc;
import java.math.BigDecimal;
public class Operacoes {
private BigDecimal[] memory = new BigDecimal[5];
public BigDecimal[] getMemory() {
return memory;
}
public Operacoes()
{
this.memory[0] = new BigDecimal(0);
}
void put(BigDecimal val){
for(int i = memory.length-1; i > 0; i--){
memory[i] = memory[i-1];
}
memory[0] = val;
}
//2
public BigDecimal adicao(BigDecimal a, BigDecimal b){
put(a.add(b));
return this.memory[0];
}
public BigDecimal sub(BigDecimal a, BigDecimal b){
put(a.subtract(b));
return this.memory[0];
}
public BigDecimal mult(BigDecimal a, BigDecimal b){
put(a.multiply(b));
return this.memory[0];
}
public BigDecimal div(BigDecimal a, BigDecimal b){
put(a.divide(b));
return this.memory[0];
}
//1
public BigDecimal adicao(BigDecimal b){
put(memory[0].add(b));
return this.memory[0];
}
public BigDecimal sub(BigDecimal b){
put(memory[0].subtract(b));
return this.memory[0];
}
public BigDecimal mult(BigDecimal b){
put(memory[0].multiply(b));
return this.memory[0];
}
public BigDecimal div(BigDecimal b){
put(memory[0].divide(b));
return this.memory[0];
}
public BigDecimal pow(BigDecimal a, int b)
{
return a.pow(b);
}
}