Advertisement
Guest User

Swimming Record

a guest
Jan 22nd, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SwimmingRecord {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. double recordInSeconds = Double.parseDouble(scan.nextLine());
  8. double distanceInMeters = Double.parseDouble(scan.nextLine());
  9. double secondsPerMeter = Double.parseDouble(scan.nextLine());
  10.  
  11. double travelTime = distanceInMeters * secondsPerMeter;
  12. double travelSlow = Math.floor(distanceInMeters / 15) * 12.5;
  13. double totalTimeTravel = travelTime / travelSlow;
  14.  
  15. if(recordInSeconds < totalTimeTravel){
  16.  
  17. System.out.printf("Yes, he succeeded! The new world record is %.2f seconds.", totalTimeTravel);
  18. }else if(totalTimeTravel<recordInSeconds){
  19.  
  20. double timeLeft =recordInSeconds - totalTimeTravel;
  21. System.out.printf("No, he failed! He was %.2f seconds slower.",timeLeft);
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement