Advertisement
IrinaIgnatova

Hello, France

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