desislava_topuzakova

05. Movie Stars

Mar 20th, 2021
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 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.         //стоп: бюджетът < 0 или ACTION
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         //command -> актьор или ACTION
  9.         //спираме: command == ACTION
  10.         //продължаваме: command != ACTION
  11.         String command = scanner.nextLine();
  12.         while(!command.equals("ACTION")) {
  13.             //АКТЬОР
  14.             String actorName = command;
  15.             double salary = 0;
  16.             //над 15 символа -> 20% от бюджета
  17.             //под 15 символа -> от конзолата
  18.             if(actorName.length() > 15) {
  19.                 salary = 0.2 * budget;
  20.             } else {
  21.                 salary = Double.parseDouble(scanner.nextLine());
  22.             }
  23.  
  24.             budget -= salary;
  25.             if(budget <= 0) {
  26.                 break;
  27.             }
  28.  
  29.             command = scanner.nextLine();
  30.         }
  31.  
  32.         //достатъчен или не
  33.         if(budget >= 0) {
  34.             System.out.printf("We are left with %.2f leva.", budget);
  35.         } else {
  36.             double needMoney = Math.abs(budget);
  37.             System.out.printf("We need %.2f leva for our actors.", needMoney);
  38.         }
  39.  
  40.  
  41.  
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment