Advertisement
IvaAnd

SwimmingPool

Feb 18th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WorldSwimmingRecord {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         // READ
  8.         //1. record in seconds to reach
  9.         //2. distance to swim in meters
  10.         //3. time in second for 1m
  11.  
  12.         // KNOW
  13.         //1. water oposition, each 15m, slows down the swimmer with 12.5sec
  14.  
  15.         double recordToReachInSecs = Double.parseDouble(scanner.nextLine());
  16.         int distanceToSwimInMeters = Integer.parseInt(scanner.nextLine());
  17.         double timeInSecsFor1meter = Double.parseDouble(scanner.nextLine());
  18.  
  19.         double timeForFullDistance = distanceToSwimInMeters * timeInSecsFor1meter; // 3017 * 5.03 = 15,175.51
  20.         double opositionInSecs = distanceToSwimInMeters / 15;
  21.         double roundDown = Math.floor(opositionInSecs);// 3017 / 15
  22.         double roundedOposition = roundDown * 12.5;//201 * 12.5=
  23.         double sumTime = timeForFullDistance + roundedOposition;
  24.  
  25.         if (recordToReachInSecs <= sumTime ){
  26.  
  27.             double missingSecs = sumTime -recordToReachInSecs ;
  28.             System.out.printf("No, he failed! He was %.2f seconds slower.", missingSecs);
  29.  
  30.         } else {
  31.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.",sumTime);
  32.         }
  33.  
  34.         }
  35.  
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement