Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class BachelorsParty {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- // 1. Read singers sum
- int singerPrice = Integer.parseInt(scanner.nextLine());
- // 2. Repeat
- String command = scanner.nextLine();
- int totalSum = 0;
- int guestsSum = 0;
- while (!command.equals("The restaurant is full")) {
- // 2.1. Read count of people in group
- int countOfPeople = Integer.parseInt(command);
- guestsSum += countOfPeople;
- // 2.2 Calculate income from group
- // 2.2.1 < 5
- if (countOfPeople < 5) {
- // totalSum = totalSum + (countOfPeople * 100)
- totalSum += countOfPeople * 100;
- } else {
- // 2.2.2 >= 5
- // 2.3. Sum to total income
- totalSum += countOfPeople * 70;
- }
- command = scanner.nextLine();
- }
- // 3. Check if we have enough money
- // 4. Print
- if (totalSum >= singerPrice) {
- System.out.printf("You have %d guests and %d leva left.",
- guestsSum, totalSum - singerPrice);
- } else {
- System.out.printf("You have %d guests and %d leva income, but no singer.",
- guestsSum, totalSum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement