Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. package org.bootcamp;
  2.  
  3. import org.bootcamp.service.InsuranceCalculationResult;
  4. import org.bootcamp.service.InsuranceCalculatorService;
  5. import org.springframework.boot.CommandLineRunner;
  6. import org.springframework.boot.SpringApplication;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8.  
  9. import java.util.List;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. @SpringBootApplication
  13. public class MainApp implements CommandLineRunner {
  14. private final InsuranceCalculatorService service;
  15. public MainApp(InsuranceCalculatorService service)
  16. {
  17. this.service=service;
  18. }
  19. @Override
  20. public void run(String... args) throws Exception {
  21.  
  22. final List<InsuranceCalculationResult> resultList1 = service.calculateAll();
  23. final List<InsuranceCalculationResult> resultList2 = service.getCostsHigherThan(1000);
  24. resultList1.forEach(MainApp::printCalculationResult);
  25. System.out.println();
  26. resultList2.forEach(MainApp::printCalculationResult);
  27. System.out.println();
  28. printCalculationResult(service.calculateById("3c997def-3cff-11e8-c243-14de190f32bc"));
  29.  
  30. }
  31. private static final String OUTPUT_FORMAT = "%s with id %s has total cost %.2f";
  32.  
  33. public static void main(String[] args) {
  34. SpringApplication.run(MainApp.class, args);
  35. }
  36.  
  37. private static void printCalculationResult(InsuranceCalculationResult result) {
  38.  
  39. if (result != null) {
  40. final String output = String.format(OUTPUT_FORMAT, result.getVehicleTypeName(), result.getId(), result.getCost());
  41. System.out.println(output);
  42. }
  43. }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement