Advertisement
Sim0o0na

04. BachelorParty

Jul 20th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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 singer price
  10. int singerPrice = Integer.parseInt(scanner.nextLine());
  11. // 2. Until the restaurant is full
  12. String command = scanner.nextLine();
  13. int sumIncome = 0;
  14. int sumPeopleCount = 0;
  15. int couvertPrice = 0;
  16. while (!command.equals("The restaurant is full")) {
  17. // 2.1. Read people cnt
  18. int peopleCount = Integer.parseInt(command);
  19. sumPeopleCount += peopleCount;
  20. // 2.2 Calculate income from group
  21. // 2.2.1 cnt < 5
  22. if (peopleCount < 5) {
  23. couvertPrice = 100;
  24. } else {
  25. // 2.2.2 cnt >= 5
  26. couvertPrice = 70;
  27. }
  28. int currentGroupIncome = peopleCount * couvertPrice;
  29. // 2.3 Sum income
  30. sumIncome = sumIncome + currentGroupIncome; // sum += currentGroupIncome
  31. command = scanner.nextLine();
  32. }
  33.  
  34. // 3. Check if income is enough
  35. String output = String.format("You have %d guests ", sumPeopleCount);
  36. String secondPartOutput = "";
  37. if (sumIncome >= singerPrice) {
  38. secondPartOutput = String.format("and %d leva left.", sumIncome - singerPrice);
  39. } else {
  40. secondPartOutput = String.format("and %d leva income, but no singer.", sumIncome);
  41. }
  42.  
  43. System.out.println(output + secondPartOutput);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement