Advertisement
Spocoman

Final Competition

Sep 6th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 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.         int dancers = Integer.parseInt(scanner.nextLine());
  7.         double points = Double.parseDouble(scanner.nextLine()),
  8.                 totalSum = dancers * points;
  9.         String season = scanner.nextLine(),
  10.                 destination = scanner.nextLine();
  11.  
  12.         if (destination.equals("Abroad")) {
  13.             totalSum *= 1.50;
  14.             if (season.equals("summer")) {
  15.                 totalSum *= 0.90;
  16.             } else {
  17.                 totalSum *= 0.85;
  18.             }
  19.         } else {
  20.             if (season.equals("summer")) {
  21.                 totalSum *= 0.95;
  22.             } else {
  23.                 totalSum *= 0.92;
  24.             }
  25.         }
  26.  
  27.         System.out.printf("Charity - %.2f\n", totalSum * 0.75);
  28.         System.out.printf("Money per dancer - %.2f\n", totalSum * 0.25 / dancers);
  29.     }
  30. }
  31.  
  32. Решение с тернарен оператор:
  33.  
  34. import java.util.Scanner;
  35.  
  36. public class Main {
  37.     public static void main(String[] args) {
  38.         Scanner scanner = new Scanner(System.in);
  39.         int dancers = Integer.parseInt(scanner.nextLine());
  40.         double points = Double.parseDouble(scanner.nextLine()),
  41.                 totalSum = dancers * points;
  42.         String season = scanner.nextLine(),
  43.                 destination = scanner.nextLine();
  44.  
  45.         totalSum *=
  46.                 destination.equals("Abroad")
  47.                         ? 1.50 * (season.equals("summer") ? 0.90 : 0.85)
  48.                         : (season.equals("summer") ? 0.95 : 0.92);
  49.  
  50.         System.out.printf("Charity - %.2f\n", totalSum * 0.75);
  51.         System.out.printf("Money per dancer - %.2f\n", totalSum * 0.25 / dancers);
  52.     }
  53. }
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement