Advertisement
myrdok123

P06WorldSwimmingRecord

Jan 15th, 2023
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package L02ConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P06WorldSwimmingRecord {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.  
  11.         //Прочитаме от конзолата
  12.         //Пресмятаме забавянето
  13.         //Резултата, за който Иван преплува разстоянието -> разстоянието * времето за 1м + забавянето
  14.         //Правим проверка дали е подобрил рекордът
  15.  
  16.         double recordInSeconds = Double.parseDouble(scanner.nextLine());
  17.         double distance = Double.parseDouble(scanner.nextLine());
  18.         double timeForOneMeter = Double.parseDouble(scanner.nextLine());
  19.  
  20.         double delay = (Math.floor(distance / 15)) * 12.5;
  21.  
  22.         double result = distance * timeForOneMeter + delay;
  23.  
  24.  
  25.         double diff = recordInSeconds - result;
  26.  
  27.         if(diff > 0){
  28.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", result);
  29.         }else {
  30.             double neededSeconds = result - recordInSeconds;
  31.             System.out.printf("No, he failed! He was %.2f seconds slower.", neededSeconds);
  32.         }
  33.     }
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement