Advertisement
GabrielHr00

06. World Swimming Record

Mar 17th, 2024
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package _02_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 distanceMeters = Double.parseDouble(scanner.nextLine());
  10.         double timeFor1Meter = Double.parseDouble(scanner.nextLine());
  11.  
  12.         double swimmingTime = distanceMeters * timeFor1Meter;
  13.  
  14.         double intervals = Math.floor(distanceMeters / 15);
  15.         double slowingTime = intervals * 12.5;
  16.  
  17.         swimmingTime = swimmingTime + slowingTime;
  18.  
  19.         if (swimmingTime < record) {
  20.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", swimmingTime);
  21.         } else {
  22.             System.out.printf("No, he failed! He was %.2f seconds slower.", swimmingTime - record);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement