Advertisement
myrdok123

08. Lunch Break

Jan 14th, 2024
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. package W02ConditionalStatements.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08LunchBreak {
  6.     public static void main(String[] args) {
  7.  
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.  
  12.  
  13.         String serialName = scanner.nextLine();
  14.         int duration = Integer.parseInt(scanner.nextLine());
  15.         int lunchBreak = Integer.parseInt(scanner.nextLine());
  16.  
  17.         //Пресмятаме колко време ще обядваме и колко време ще ни е почивка
  18.         double timeForEat = lunchBreak / 8.0;
  19.         double timeForRest = lunchBreak / 4.0;
  20.  
  21.         //Пресмятаме времето за гледане на сериала
  22.         double timeForWatch = lunchBreak - timeForEat - timeForRest;
  23.  
  24.         //Проверяваме дали оставащото време е достатъчно, за да изгледаме 1 серия от сериала
  25.  
  26.  
  27.  
  28.         double diff = Math.ceil(Math.abs(timeForWatch - duration));
  29.  
  30.  
  31.         if (timeForWatch >= duration){
  32.             System.out.printf("You have enough time to watch %s and left with %.0f minutes free time.",
  33.                     serialName, diff);
  34.         }else {
  35.             System.out.printf("You don't have enough time to watch %s, you need %.0f more minutes.",
  36.                     serialName, diff);
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement