-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrencyTable.java
More file actions
60 lines (53 loc) · 1.23 KB
/
CurrencyTable.java
File metadata and controls
60 lines (53 loc) · 1.23 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
package ac.shenkar.Calc;
//Database of currency table
public class CurrencyTable {
private int ROWS;
//array of currency
private Currency[] row;
public CurrencyTable(int size) {
ROWS=size;
this.row = new Currency[ROWS];
}
//add currency to table
public void addElement(int index,Currency curr){
row[index]=curr;
}
//return table as Object class for presenting on TableGUI
public Object[][] getTable(){
Object[][] table=new Object[ROWS+1][3];
table[0][0]="CODE";
table[0][1]="RATE";
table[0][2]="CHANGE";
for(int i=0;i<ROWS;i++){
table[i+1][0]=row[i].getCode();
table[i+1][1]=row[i].getRate();
table[i+1][2]=row[i].getChange();
}
return table;
}
//get currency at row
public Currency getRow(int i){
return row[i];
}
public double calc(double sum, String to, String from) {
double _rate = 1;
if(from.equals("ILS"))
_rate = 1;
for (int i = 0; i < this.row.length; i++) {
if(row[i].getCode().equals(from)) {
_rate = row[i].getRate();
break;
}
}
double _from = sum * _rate;
if(to.equals("ILS"))
_rate = 1;
for (int i = 0; i < this.row.length; i++) {
if(row[i].getCode().equals(to)) {
_rate = row[i].getRate();;
break;
}
}
return _from / _rate;
}
}