Advertisement
veronikaaa86

04. Club

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