Advertisement
damesova

Hello, France [Mimi]

Apr 15th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class _02_Task {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String input = scanner.nextLine();
  10.         double budget = Double.parseDouble(scanner.nextLine());
  11.         String[] line = input.split("\\|");
  12.  
  13.         List<Double> buy = new ArrayList<>();
  14.  
  15.         double maxClothes = 50.00;
  16.         double maxShoes = 35.00;
  17.         double maxAcc = 20.50;
  18.         double initialSum = 0;
  19.         for (int i = 0; i < line.length; i++) {
  20.             String[] elem = line[i].split("->");
  21.             double price = Double.parseDouble(elem[1]);
  22.  
  23.             if (budget < price) {
  24.                 continue;
  25.             }
  26.  
  27.             switch (elem[0]) {
  28.                 case "Clothes":
  29.                     if (price <= maxClothes) {
  30.                         initialSum += price;
  31.                         budget -= Double.parseDouble(elem[1]);
  32.                         price += Double.parseDouble(elem[1]) * 0.4;
  33.  
  34.                         buy.add(price);
  35.                     }
  36.                     break;
  37.                 case "Shoes":
  38.                     if (price <= maxShoes) {
  39.                         initialSum += price;
  40.                         budget -= Double.parseDouble(elem[1]);
  41.                         price += Double.parseDouble(elem[1]) * 0.4;
  42.  
  43.                         buy.add(price);
  44.                     }
  45.                     break;
  46.                 case "Accessories":
  47.                     if (price <= maxAcc) {
  48.                         initialSum += price;
  49.                         budget -= Double.parseDouble(elem[1]);
  50.                         price += Double.parseDouble(elem[1]) * 0.4;
  51.  
  52.                         buy.add(price);
  53.                     }
  54.                     break;
  55.  
  56.             }
  57.         }
  58.  
  59.         double sum = 0;
  60.         for (Double price : buy) {
  61.             sum += price;
  62.             System.out.printf("%.2f", price);
  63.             System.out.print(" ");
  64.         }
  65.         System.out.println();
  66.  
  67.         System.out.print("Profit: ");
  68.         double profit = sum - initialSum;
  69.         System.out.printf("%.2f%n", profit);
  70.  
  71.  
  72.         if (sum + budget>= 150.00) {
  73.             System.out.println("Hello, France!");
  74.         } else {
  75.             System.out.println("Time to go.");
  76.         }
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement