Advertisement
desislava_topuzakova

04. Running in the park

May 21st, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RunningInThePark {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         double sumDistance = 0.0;
  10.         int totalCalories = 0;
  11.         int caloriesPerMinute = 20;
  12.         double totalDistance = 0;
  13.         int totalMinutes = 0;
  14.  
  15.         for (int i = 0; i < n; i++) {
  16.             int minutesRun = Integer.parseInt(scanner.nextLine());
  17.             double distance = Double.parseDouble(scanner.nextLine());
  18.             String metric = scanner.nextLine();
  19.  
  20.             if (metric.equals("m")) {
  21.                 distance = distance / 1000;
  22.             }
  23.  
  24.             int currentCalories = minutesRun * caloriesPerMinute;
  25.  
  26.             totalMinutes += minutesRun;
  27.             totalCalories += currentCalories;
  28.             totalDistance += distance;
  29.         }
  30.  
  31.         System.out.printf("He ran %.2fkm for %d minutes and burned %d calories.",
  32.                 totalDistance,
  33.                 totalMinutes,
  34.                 totalCalories);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement