Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ExamPreparation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //за всеки един сериал:
- //1. име
- //2. цена
- //3. проверка за намаление на цената
- //4. купуваме (бюджета - цена на филма)
- // проверка дали бюджетът е достатъчен след всички сериали
- double budget = Double.parseDouble(scanner.nextLine());
- int countSeries = Integer.parseInt(scanner.nextLine());
- for (int serial = 1; serial <= countSeries; serial++) {
- String name = scanner.nextLine();
- double price = Double.parseDouble(scanner.nextLine());
- switch(name) {
- case "Thrones":
- price = price - 0.50 * price; //price * 0.5;
- break;
- case "Lucifer":
- price = price - 0.40 * price; //price * 0.6;
- break;
- case "Protector":
- price = price - 0.30 * price;//price * 0.7;
- break;
- case "TotalDrama":
- price = price - 0.20 * price;//price * 0.8;
- break;
- case "Area":
- price = price - 0.10 * price; //0.9 * price;
- break;
- }
- budget -= price;
- }
- //бюджетът е достатъчен
- if(budget >= 0) {
- System.out.printf("You bought all the series and left with %.2f lv.", budget);
- } else {
- //-4
- System.out.printf("You need %.2f lv. more to buy the series!", Math.abs(budget));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment