Advertisement
Lyubohd

04. Bachelor Party

Dec 10th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem04 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         //•   Сумата предвидена за гост изпълнителя - цяло число в интервала [1… 4500]
  8.         //•"The restaurant is full") - броят на хората във всяка група.
  9.         String input = scan.nextLine();
  10.         int target = Integer.parseInt(input); //Integer.parseInt(scan.nextLine());
  11.         int money = 0;
  12.         int totalPeopleCnt = 0;
  13.  
  14.         String data = scan.nextLine();
  15.         while (!"The restaurant is full".equals(data)) {
  16.             int peopleCnt = Integer.parseInt(data);
  17.             totalPeopleCnt += peopleCnt;
  18.             if (peopleCnt < 5) {
  19.                 money = money + (peopleCnt * 100);
  20.             } else {
  21.                 money = money + (peopleCnt * 70);
  22.             }
  23.  
  24.             data = scan.nextLine();
  25.         }
  26.  
  27.         //•   Ако Марто успее да си позволи гост изпълнител:
  28.         //"You have {брой гости} guests and {останалата сума} leva left."
  29.         //•   Ако Марто не успее да си позволи гост изпълнител:
  30.         //"You have {брой гости} guests and {приходи} leva income, but no singer."
  31.  
  32.         if (money >= target) {
  33.             int moneyLeft = money - target;
  34.             System.out.printf("You have %d guests and %d leva left.", totalPeopleCnt, moneyLeft);
  35.         } else {
  36.             System.out.printf("You have %d guests and %d leva income, but no singer.", totalPeopleCnt, money);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement