Advertisement
Spocoman

World Snooker Championship

Sep 11th, 2024
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 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.         String stageOfTheChampionship = scanner.nextLine(),
  7.                 typesOfTickets = scanner.nextLine();
  8.         int ticketCount = Integer.parseInt(scanner.nextLine());
  9.         String selfieWithTheTrophy = scanner.nextLine();
  10.         double ticketPrice = 0, totalPrice;
  11.  
  12.         if (stageOfTheChampionship.equals("Quarter final")) {
  13.             if (typesOfTickets.equals("Standard")) {
  14.                 ticketPrice = 55.50;
  15.             } else if (typesOfTickets.equals("Premium")) {
  16.                 ticketPrice = 105.20;
  17.             } else if (typesOfTickets.equals("VIP")) {
  18.                 ticketPrice = 118.90;
  19.             }
  20.         } else if (stageOfTheChampionship.equals("Semi final")) {
  21.             if (typesOfTickets.equals("Standard")) {
  22.                 ticketPrice = 75.88;
  23.             } else if (typesOfTickets.equals("Premium")) {
  24.                 ticketPrice = 125.22;
  25.             } else if (typesOfTickets.equals("VIP")) {
  26.                 ticketPrice = 300.40;
  27.             }
  28.         } else if (stageOfTheChampionship.equals("Final")) {
  29.             if (typesOfTickets.equals("Standard")) {
  30.                 ticketPrice = 110.10;
  31.             } else if (typesOfTickets.equals("Premium")) {
  32.                 ticketPrice = 160.66;
  33.             } else if (typesOfTickets.equals("VIP")) {
  34.                 ticketPrice = 400.00;
  35.             }
  36.         }
  37.  
  38.         totalPrice = ticketPrice * ticketCount;
  39.  
  40.         if (totalPrice > 4000) {
  41.             totalPrice *= 0.75;
  42.             selfieWithTheTrophy = "N";
  43.         } else if (totalPrice > 2500) {
  44.             totalPrice *= 0.90;
  45.         }
  46.  
  47.         if (selfieWithTheTrophy.equals("Y")) {
  48.             totalPrice += ticketCount * 40;
  49.         }
  50.  
  51.         System.out.printf("%.2f\n", totalPrice);
  52.     }
  53. }
  54.  
  55. Решение със switch и тернарен оператор:
  56.  
  57. import java.util.Scanner;
  58.  
  59. public class Main {
  60.     public static void main(String[] args) {
  61.         Scanner scanner = new Scanner(System.in);
  62.         String stageOfTheChampionship = scanner.nextLine(),
  63.                 typesOfTickets = scanner.nextLine();
  64.         int ticketCount = Integer.parseInt(scanner.nextLine());
  65.         String selfieWithTheTrophy = scanner.nextLine();
  66.  
  67.         double ticketPrice = switch (stageOfTheChampionship) {
  68.             case "Quarter final" -> switch (typesOfTickets) {
  69.                 case "Standard" -> 55.50;
  70.                 case "Premium" -> 105.20;
  71.                 case "VIP" -> 118.90;
  72.                 default -> 0;
  73.             };
  74.             case "Semi final" -> switch (typesOfTickets) {
  75.                 case "Standard" -> 75.88;
  76.                 case "Premium" -> 125.22;
  77.                 case "VIP" -> 300.40;
  78.                 default -> 0;
  79.             };
  80.             case "Final" -> switch (typesOfTickets) {
  81.                 case "Standard" -> 110.10;
  82.                 case "Premium" -> 160.66;
  83.                 case "VIP" -> 400.00;
  84.                 default -> 0;
  85.             };
  86.             default -> 0;
  87.         };
  88.  
  89.         double totalPrice = ticketPrice * ticketCount;
  90.         selfieWithTheTrophy = totalPrice > 4000 ? "N" : selfieWithTheTrophy;
  91.         totalPrice *= totalPrice > 4000 ? 0.75 : totalPrice > 2500 ? 0.90 : 1;
  92.         totalPrice += selfieWithTheTrophy.equals("Y") ? ticketCount * 40 : 0;
  93.  
  94.         System.out.printf("%.2f\n", totalPrice);
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement