-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBilheteUnico.dart
50 lines (41 loc) · 1.17 KB
/
BilheteUnico.dart
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
class BilheteUnico {
double saldo = 0.0;
double valorDiaUtil = 0.0;
double valorDiaFds = 0.0;
LinkedHashMap valorPorDia ;
BilheteUnico(double saldo, double valorDiaUtil, [double valorDiaFds = 0.0]){
this.saldo = saldo;
this.valorDiaUtil = valorDiaUtil;
this.valorDiaFds = valorDiaFds;
this.valorPorDia = new LinkedHashMap();
}
void adicionaSaldo(double newSaldo){
saldo += newSaldo;
}
bool temSaldo([double currSaldo]){
if(currSaldo == null){
currSaldo = saldo;
}
return currSaldo > valorDiaFds && currSaldo > valorDiaUtil;
}
Date proximaRecarga([Date now]){
if(now == null){
now = new Date.now().add(new Duration(1));
}
double currSaldo = saldo;
Date currDate = now;
while(temSaldo(currSaldo)){
if(currDate.weekday == Date.SAT || currDate.weekday == Date.SUN){
currSaldo -= valorDiaFds;
} else {
currSaldo -= valorDiaUtil;
}
valorPorDia[Utils.formatDate(currDate)] = currSaldo;
currDate = currDate.add(new Duration(1));
}
return currDate;
}
toString(){
return "Saldo: $saldo, valor dia util: $valorDiaUtil";
}
}