Advertisement
Spocoman

01. Match Tickets

Aug 26th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MatchTickets {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double budget = Double.parseDouble(scanner.nextLine());
  7.         String category = scanner.nextLine();
  8.         int people = Integer.parseInt(scanner.nextLine());
  9.  
  10.         double sum = 0;
  11.  
  12.         if (people >= 1 && people <= 4) {
  13.             budget *= 0.25;
  14.         } else if (people > 4 && people <= 9) {
  15.             budget *= 0.40;
  16.         } else if (people > 9 && people <= 24) {
  17.             budget *= 0.50;
  18.         } else if (people > 24 && people < 50) {
  19.             budget *= 0.60;
  20.         } else {
  21.             budget *= 0.75;
  22.         }
  23.  
  24.         if (category.equals("VIP")) {
  25.             sum = 499.99 * people;
  26.         } else if (category.equals("Normal")) {
  27.             sum = 249.99 * people;
  28.         }
  29.  
  30.         if (budget >= sum) {
  31.             System.out.printf("Yes! You have %.2f leva left.", budget - sum);
  32.         } else {
  33.             System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
  34.         }
  35.     }
  36. }
  37.  
  38. ИЛИ:
  39.  
  40. import java.util.Scanner;
  41.  
  42. public class MatchTickets {
  43.     public static void main(String[] args) {
  44.         Scanner scanner = new Scanner(System.in);
  45.         double budget = Double.parseDouble(scanner.nextLine());
  46.         String category = scanner.nextLine();
  47.         int people = Integer.parseInt(scanner.nextLine());
  48.  
  49.         budget *=
  50.                 people >= 1 && people <= 4 ? 0.25 :
  51.                         people > 4 && people <= 9 ? 0.40 :
  52.                                 people > 9 && people <= 24 ? 0.50 :
  53.                                         people > 24 && people < 50 ? 0.60 : 0.75;
  54.  
  55.         double sum = (category.equals("VIP") ? 499.99 : 249.99) * people;
  56.        
  57.         if (budget >= sum) {
  58.             System.out.printf("Yes! You have %.2f leva left.", budget - sum);
  59.         } else {
  60.             System.out.printf("Not enough money! You need %.2f leva.", sum - budget);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement