Advertisement
SophiYo

WorldSwimmingRecord

Dec 16th, 2018
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package O3_ConditionalConstructions.Exercise;
  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.  
  9.         double recordSeconds = Double.parseDouble(scanner.nextLine());
  10.         double distanceM = Double.parseDouble(scanner.nextLine());
  11.         double timeInSecondsForMeter = Double.parseDouble(scanner.nextLine());
  12.  
  13.         double neededTime = distanceM * timeInSecondsForMeter;
  14.         double resistanceCumulation = Math.floor(distanceM / 15) * 12.5;
  15.         double totalTime = neededTime + resistanceCumulation;
  16.  
  17.         if (recordSeconds <= totalTime) {
  18.             double deficit = Math.abs(recordSeconds - totalTime);
  19.             System.out.printf("No, he failed! He was %.2f seconds slower.", deficit);
  20.         } else if (recordSeconds > totalTime){
  21.             System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", totalTime);
  22.         }
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement