Advertisement
GabrielHr00

06. World Swimming Record

May 21st, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. package S2_ConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WorldSwimmingRecord {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         double record = Double.parseDouble(scanner.nextLine());
  9.         double distance = Double.parseDouble(scanner.nextLine());
  10.         double timeFor1Meter = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double timeForSwimming = distance * timeFor1Meter;
  13.  
  14.         double sectorsInDistance = Math.floor(distance / 15);
  15.         double slowingTime = sectorsInDistance * 12.5;
  16.  
  17.         timeForSwimming = timeForSwimming + slowingTime;
  18.  
  19.         if(timeForSwimming < record) {
  20.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", timeForSwimming);
  21.         } else {
  22.             double diff = timeForSwimming - record;
  23.             System.out.printf("No, he failed! He was %.2f seconds slower.", diff);
  24.         }
  25.  
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement