Lyubohd

03. World Snooker Championship

Dec 10th, 2019
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem03 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         //1.    +Етап на първенството – текст - “Quarter final ”, “Semi final” или “Final”
  8.         //2.    +Вид на билета – текст - “Standard”, “Premium” или “VIP”
  9.         //3.    +Брой билети – цяло число в интервала [1 … 30]
  10.         //4.    +Снимка с трофея – символ – 'Y' (да) или 'N' (не)
  11.         String stage = scan.nextLine();
  12.         String ticketType = scan.nextLine();
  13.         int ticketsCnt = Integer.parseInt(scan.nextLine());
  14.         String photo = scan.nextLine();
  15.         boolean hasTax = false;
  16.         if (photo.equals("Y")) {
  17.             hasTax = true;
  18.         }
  19.  
  20.         double price = 0.0;
  21.  
  22.         switch (stage) {
  23.             //“Standard”, “Premium” или “VIP”
  24.             case "Quarter final":
  25.                 if (ticketType.equals("Standard")) {
  26.                     price = 55.50;
  27.                 } else if (ticketType.equals("Premium")) {
  28.                     price = 105.20;
  29.                 } else if (ticketType.equals("VIP")) {
  30.                     price = 118.90;
  31.                 }
  32.                 break;
  33.             case "Semi final":
  34.                 if (ticketType.equals("Standard")) {
  35.                     price = 75.88;
  36.                 } else if (ticketType.equals("Premium")) {
  37.                     price = 125.22;
  38.                 } else if (ticketType.equals("VIP")) {
  39.                     price = 300.40;
  40.                 }
  41.                 break;
  42.             case "Final":
  43.                 if (ticketType.equals("Standard")) {
  44.                     price = 110.10;
  45.                 } else if (ticketType.equals("Premium")) {
  46.                     price = 160.66;
  47.                 } else if (ticketType.equals("VIP")) {
  48.                     price = 400;
  49.                 }
  50.                 break;
  51.         }
  52.         double totalPrice = price * ticketsCnt; // 5 * (Final VIP) - 400
  53.  
  54.         if (totalPrice > 4000) {
  55.             totalPrice = totalPrice - totalPrice * 0.25; // totalPrice * 0.75;
  56.             hasTax = false;
  57.         } else if (totalPrice > 2500) {
  58.             totalPrice = totalPrice - totalPrice * 0.1;// totalPrice * 0.9
  59.         }
  60.  
  61.         if (hasTax) {
  62.             totalPrice = totalPrice + (ticketsCnt * 40);
  63.         }
  64.  
  65.         System.out.printf("%.2f", totalPrice);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment