fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. public class Country {
  8.  
  9. private String name;
  10. private String date;
  11. private int confirmed_diff;
  12. private float fatality_rate;
  13. }
  14. public class CountryDto {
  15.  
  16. private List<CountryDataDto> data;
  17. }
  18. public class CountryDataDto {
  19.  
  20. private CountryRegionDto region;
  21. private String date;
  22. private int confirmed_diff;
  23. private float fatality_rate;
  24.  
  25. }
  26.  
  27. public class CountryRegionDto {
  28.  
  29. private String name;
  30. }
  31. public class CountryService {
  32.  
  33.  
  34.  
  35. public List<Country> getCoutries()
  36. {
  37. RestTemplate restTemplate; = new RestTemplate();
  38. HttpHeaders headers = new HttpHeaders();
  39. headers.set("x-rapidapi-host","covid-19-statistics.p.rapidapi.com");
  40. headers.set("x-rapidapi-key","cdd95c2ed2msh46d1517fc73ea3dp1d7e84jsn0ec3a82ea7ae");
  41. HttpEntity entity = new HttpEntity(headers);
  42. ResponseEntity<CountryDto> response = restTemplate.exchange("https://c...content-available-to-author-only...i.com/reports", HttpMethod.GET,entity, CountryDto.class);
  43. CountryDto country = response.getBody();
  44.  
  45. List<Country> countries = new LinkedList<>();
  46. countries.add(Country.builder()
  47. .name(country.getData().get(0).getRegion().getName())
  48. .confirmed_diff(country.getData().get(0).getConfirmed_diff())
  49. .date(country.getData().get(0).getDate())
  50. .fatality_rate(country.getData().get(0).getFatality_rate())
  51. .build());
  52. return countries;
  53. }
  54. }
  55.  
  56. /* Name of the class has to be "Main" only if the class is public. */
  57. class Ideone
  58. {
  59. public static void main (String[] args) throws java.lang.Exception
  60. {
  61. // your code goes here
  62. }
  63. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:37: error: illegal start of expression
    	RestTemplate restTemplate; = new RestTemplate();
    	                           ^
1 error
stdout
Standard output is empty