Advertisement
Sim0o0na

BachelorsParty

Jul 4th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class BachelorsParty {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         // 1. Read singers sum
  10.         int singerPrice = Integer.parseInt(scanner.nextLine());
  11.         // 2. Repeat
  12.         String command = scanner.nextLine();
  13.         int totalSum = 0;
  14.         int guestsSum = 0;
  15.         while (!command.equals("The restaurant is full")) {
  16.             // 2.1. Read count of people in group
  17.             int countOfPeople = Integer.parseInt(command);
  18.             guestsSum += countOfPeople;
  19.             // 2.2 Calculate income from group
  20.             // 2.2.1 < 5
  21.             if (countOfPeople < 5) {
  22.                 // totalSum = totalSum + (countOfPeople * 100)
  23.                 totalSum += countOfPeople * 100;
  24.             } else {
  25.                 // 2.2.2 >= 5
  26.                 // 2.3. Sum to total income
  27.                 totalSum += countOfPeople * 70;
  28.             }
  29.             command = scanner.nextLine();
  30.         }
  31.  
  32.         // 3. Check if we have enough money
  33.         // 4. Print
  34.         if (totalSum >= singerPrice) {
  35.             System.out.printf("You have %d guests and %d leva left.",
  36.                     guestsSum, totalSum - singerPrice);
  37.         } else {
  38.             System.out.printf("You have %d guests and %d leva income, but no singer.",
  39.                     guestsSum, totalSum);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement