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 singer price
- int singerPrice = Integer.parseInt(scanner.nextLine());
- // 2. Until the restaurant is full
- String command = scanner.nextLine();
- int sumIncome = 0;
- int sumPeopleCount = 0;
- int couvertPrice = 0;
- while (!command.equals("The restaurant is full")) {
- // 2.1. Read people cnt
- int peopleCount = Integer.parseInt(command);
- sumPeopleCount += peopleCount;
- // 2.2 Calculate income from group
- // 2.2.1 cnt < 5
- if (peopleCount < 5) {
- couvertPrice = 100;
- } else {
- // 2.2.2 cnt >= 5
- couvertPrice = 70;
- }
- int currentGroupIncome = peopleCount * couvertPrice;
- // 2.3 Sum income
- sumIncome = sumIncome + currentGroupIncome; // sum += currentGroupIncome
- command = scanner.nextLine();
- }
- // 3. Check if income is enough
- String output = String.format("You have %d guests ", sumPeopleCount);
- String secondPartOutput = "";
- if (sumIncome >= singerPrice) {
- secondPartOutput = String.format("and %d leva left.", sumIncome - singerPrice);
- } else {
- secondPartOutput = String.format("and %d leva income, but no singer.", sumIncome);
- }
- System.out.println(output + secondPartOutput);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement