Advertisement
veronikaaa86

04. Club

Aug 14th, 2021
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double profit = Double.parseDouble(scanner.nextLine());
  8.  
  9. double totalSum = 0;
  10. String input = scanner.nextLine();
  11. while (!input.equals("Party!")) {
  12. String cocktailName = input;
  13. int countCocktails = Integer.parseInt(scanner.nextLine());
  14.  
  15. int priceCocktail = cocktailName.length();
  16.  
  17. double sumCocktails = countCocktails * priceCocktail;
  18.  
  19. if (sumCocktails % 2 != 0) {
  20. sumCocktails = sumCocktails * 0.75;
  21. }
  22.  
  23. totalSum = totalSum + sumCocktails;
  24.  
  25. if (totalSum >= profit) {
  26. break;
  27. }
  28.  
  29. input = scanner.nextLine();
  30. }
  31.  
  32. double diff = Math.abs(profit - totalSum);
  33. if (input.equals("Party!")) {
  34. System.out.printf("We need %.2f leva more.%n", diff);
  35. } else if (totalSum >= profit) {
  36. System.out.println("Target acquired.");
  37. }
  38.  
  39. System.out.printf("Club income - %.2f leva.", totalSum);
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement