Advertisement
IvaAnd

WorldSwimmingRecord

Feb 22nd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 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.         double distanceToSwimInMeters = Integer.parseInt(scanner.nextLine());
  17.         double timeInSecsFor1meter = Double.parseDouble(scanner.nextLine());
  18.  
  19.         double timeForFullDistance = distanceToSwimInMeters * timeInSecsFor1meter;
  20.         double opositionInSecs = Math.floor (distanceToSwimInMeters / 15 );
  21.                 double roundedOposition = opositionInSecs * 12.5;
  22.         double sumTime = timeForFullDistance + roundedOposition;
  23.  
  24.         if (sumTime >= recordToReachInSecs  ){
  25.  
  26.             double missingSecs = sumTime -recordToReachInSecs ;
  27.             System.out.printf("No, he failed! He was %.2f seconds slower.", missingSecs);
  28.  
  29.         } else {
  30.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.",sumTime);
  31.         }
  32.  
  33.         }
  34.  
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement