desislava_topuzakova

2. Skeleton

May 22nd, 2021
896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PrintAndSum_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //спечелено време = пъти печели време (общо растояние / 120) * 2.5
  7.         //време за пързаляне = (общ разстояние / 100) * сек за 100 м
  8.         // времето на Марин = време за пързаляне - спечелено време
  9.         // проверим дали времето покрива контролата
  10.  
  11.         int controlMinutes = Integer.parseInt(scanner.nextLine());
  12.         int controlSeconds = Integer.parseInt(scanner.nextLine());
  13.         double length = Double.parseDouble(scanner.nextLine());
  14.         int secondsFor100Metres = Integer.parseInt(scanner.nextLine());
  15.  
  16.         double additionalTime = (length / 120) * 2.5;
  17.         double slopeTime = (length / 100) * secondsFor100Metres;
  18.         double totalTime = slopeTime - additionalTime;
  19.  
  20.         //контролното време в сек
  21.         int controlTimeSeconds = controlMinutes * 60 + controlSeconds;
  22.  
  23.         //проверка за квота
  24.         if(totalTime <= controlTimeSeconds) {
  25.             System.out.println("Marin Bangiev won an Olympic quota!");
  26.             System.out.printf("His time is %.3f.", totalTime);
  27.         } else {
  28.             double needSeconds = totalTime - controlTimeSeconds;
  29.             System.out.printf("No, Marin failed! He was %.3f second slower.",needSeconds);
  30.         }
  31.  
  32.  
  33.  
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment