Advertisement
Spocoman

Movie Destination

Sep 8th, 2024 (edited)
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget = Double.parseDouble(scanner.nextLine()),
  7.                 daySum;
  8.         String destination = scanner.nextLine(),
  9.                 season = scanner.nextLine();
  10.         int days = Integer.parseInt(scanner.nextLine());
  11.  
  12.         if (destination.equals("Dubai")) {
  13.             if (season.equals("Winter")) {
  14.                 daySum = 45000;
  15.             } else {
  16.                 daySum = 40000;
  17.             }
  18.             daySum *= 0.70;
  19.         } else if (destination.equals("Sofia")) {
  20.             if (season.equals("Winter")) {
  21.                 daySum = 17000;
  22.             } else {
  23.                 daySum = 12500;
  24.             }
  25.             daySum *= 1.25;
  26.         } else {
  27.             if (season.equals("Winter")) {
  28.                 daySum = 24000;
  29.             } else {
  30.                 daySum = 20250;
  31.             }
  32.         }
  33.  
  34.         double totalSum = daySum * days;
  35.  
  36.         if (totalSum <= budget) {
  37.             System.out.printf("The budget for the movie is enough! We have %.2f leva left!\n", budget - totalSum);
  38.         } else {
  39.             System.out.printf("The director needs %.2f leva more!\n", totalSum - budget);
  40.         }
  41.     }
  42. }
  43.  
  44. Решение с тернарен оператор:
  45.  
  46. import java.util.Scanner;
  47.  
  48. public class Main {
  49.     public static void main(String[] args) {
  50.         Scanner scanner = new Scanner(System.in);
  51.         double budget = Double.parseDouble(scanner.nextLine());
  52.         String destination = scanner.nextLine(),
  53.                 season = scanner.nextLine();
  54.         int days = Integer.parseInt(scanner.nextLine());
  55.  
  56.         budget -=
  57.                 (destination.equals("Dubai") ? (season.equals("Winter") ? 45000 : 40000) * 0.70 :
  58.                         destination.equals("Sofia") ? (season.equals("Winter") ? 17000 : 12500) * 1.25 :
  59.                                 season.equals("Winter") ? 24000 : 20250) * days;
  60.  
  61.         System.out.printf(
  62.                 budget >= 0
  63.                         ? "The budget for the movie is enough! We have %.2f leva left!\n"
  64.                         : "The director needs %.2f leva more!\n", Math.abs(budget)
  65.         );
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement