Advertisement
Valantina

Club/Ex/Java

Jul 9th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P04_Club {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double target = Double.parseDouble(scan.nextLine());
  8.         String cocktail = scan.nextLine();
  9.         double income = 0.0;
  10.  
  11.         while (!"Party!".equals(cocktail)) {
  12.             int quantity = Integer.parseInt(scan.nextLine());
  13.  
  14.             int price = quantity * cocktail.length();
  15.             double finalPrice = price;
  16.             if (price % 2 != 0) {
  17.                 finalPrice *= 0.75;
  18.             }
  19.             income += finalPrice;
  20.             target -= finalPrice;
  21.             if (target <= 0) {
  22.                 break;
  23.             }
  24.  
  25.             cocktail = scan.nextLine();
  26.         }
  27.  
  28.         if ("Party!".equals(cocktail)) {
  29.             System.out.println(String.format("We need %.2f leva more.", target));
  30.         } else {
  31.             System.out.println("Target acquired.");
  32.         }
  33.  
  34.         System.out.println(String.format("Club income - %.2f leva.", income));
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement