desislava_topuzakova

04. Series

Mar 20th, 2021
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExamPreparation {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //за всеки един сериал:
  7.             //1. име
  8.             //2. цена
  9.             //3. проверка за намаление на цената
  10.             //4. купуваме (бюджета - цена на филма)
  11.         // проверка дали бюджетът е достатъчен след всички сериали
  12.  
  13.         double budget = Double.parseDouble(scanner.nextLine());
  14.         int countSeries = Integer.parseInt(scanner.nextLine());
  15.  
  16.         for (int serial = 1; serial <= countSeries; serial++) {
  17.             String name = scanner.nextLine();
  18.             double price = Double.parseDouble(scanner.nextLine());
  19.             switch(name) {
  20.                 case "Thrones":
  21.                     price = price - 0.50 * price; //price * 0.5;
  22.                     break;
  23.                 case "Lucifer":
  24.                     price = price - 0.40 * price; //price * 0.6;
  25.                     break;
  26.                 case "Protector":
  27.                     price = price - 0.30 * price;//price * 0.7;
  28.                     break;
  29.                 case "TotalDrama":
  30.                     price = price - 0.20 * price;//price * 0.8;
  31.                     break;
  32.                 case "Area":
  33.                     price = price - 0.10 * price; //0.9 * price;
  34.                     break;
  35.             }
  36.             budget -= price;
  37.         }
  38.  
  39.         //бюджетът е достатъчен
  40.         if(budget >= 0) {
  41.             System.out.printf("You bought all the series and left with %.2f lv.", budget);
  42.         } else {
  43.             //-4
  44.             System.out.printf("You need %.2f lv. more to buy the series!", Math.abs(budget));
  45.         }
  46.  
  47.  
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment