Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Turini committed Mar 14, 2014
1 parent ff252f1 commit aacfdfe
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/main/java/br/com/casadocodigo/java8/Capitulo11.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -114,6 +116,12 @@ public Optional<LocalDateTime> getEnd() {
public Customer getCustomer() {
return customer;
}

public BigDecimal getTotalPaidMonths() {

return BigDecimal.valueOf(ChronoUnit.MONTHS.between(
getBegin(), getEnd().orElse(LocalDateTime.now())));
}
}


Expand Down Expand Up @@ -214,15 +222,37 @@ public static void main (String... args) throws Exception {

// subscriptions

BigDecimal monthlyFee = new BigDecimal("179.90");

Subscription s1 = new Subscription(monthlyFee,
today.minusMonths(5), Optional.empty(), paulo);

Subscription s2 = new Subscription(monthlyFee,
today.minusMonths(2), Optional.of(today.plusMonths(5)), rodrigo);

Subscription s3 = new Subscription(monthlyFee,
today.minusMonths(1), Optional.of(today.plusMonths(1)), adriano);

List<Subscription> subscriptions = Arrays.asList(s1, s2, s3);


// dada uma unica subscription, calcular quanto ele pagou ate hoje
// algo como calculaMesesEntre(subscription.getBegin(), subscription.getEnd().orElse(today))
// e ai multiplica pelo mnthlyFee

s1.getTotalPaidMonths().multiply(s1.getMonthlyFee());

// dada uma colecao de subscription, calcular quanto todos pagaram ate hoje

subscriptions.stream()
.map(s -> s.getMonthlyFee().multiply(s.getTotalPaidMonths()))
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO);

// achar o usuario que mais pagou total de valor de subscriptions ate hoje


// achar o usuario que ficou mais meses pagando (independente dela estar ativa ou nao)

}

}
}
}

0 comments on commit aacfdfe

Please sign in to comment.