Advertisement
Tsuki11

HelloFrance

Feb 27th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.50 KB | None | 0 0
  1. package HelloFrance;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         Scanner scan = new Scanner(System.in);
  10.         List<String> items = getInput(scan);
  11.  
  12.         double budget = Double.parseDouble(scan.nextLine());
  13.  
  14.         double clothesPrice = 50.0;
  15.         double shoesPrice = 35.00;
  16.         double accessoriesPrice = 20.50;
  17.  
  18.         int countItems = 0;
  19.         int countPrice = 1;
  20.         boolean hasBudget = true;
  21.         double profit = 0;
  22.         while (countPrice <= items.size() - 1) {
  23.  
  24.             String item = items.get(countItems);
  25.             double price = Double.parseDouble(items.get(countPrice));
  26.             if ("Clothes".equals(item)) {
  27.                 if (price <= clothesPrice && budget >= price){
  28.                     budget-=price;
  29.                     double diff = (price*1.4)-price;
  30.                     profit+=diff;
  31.                     String set = String.valueOf(price*=1.40);
  32.                     items.set(countPrice,set);
  33.                     hasBudget = true;
  34.                 }  else{
  35.                     items.remove(countItems);
  36.                     items.remove(countItems);
  37.                     hasBudget = false;
  38.                 }
  39.             } else if ("Shoes".equals(item)) {
  40.                 if (price <= shoesPrice && budget >= price) {
  41.                     budget-=price;
  42.                     double diff = (price*1.4)-price;
  43.                     profit+=diff;
  44.                     String set = String.valueOf(price*=1.40);
  45.                     items.set(countPrice,set);
  46.                     hasBudget = true;
  47.                 } else {
  48.                     items.remove(countItems);
  49.                     items.remove(countItems);
  50.                     hasBudget = false;
  51.                 }
  52.             } else if ("Accessories".equals(item)) {
  53.                 hasBudget = true;
  54.                 if (budget >=price && price <= accessoriesPrice ){
  55.                     budget-=price;
  56.                     double diff = (price*1.4)-price;
  57.                     profit+=diff;
  58.                     String set = String.valueOf(price*=1.40);
  59.                     items.set(countPrice,set);
  60.                     hasBudget = true;
  61.                 }  else{
  62.                     items.remove(countItems);
  63.                     items.remove(countItems);
  64.                     hasBudget = false;
  65.                 }
  66.  
  67.             }
  68.             if (hasBudget) {
  69.                 countItems += 2;
  70.                 countPrice += 2;
  71.             }
  72.  
  73.         }
  74.             double saveMoney = budget;
  75.  
  76.         for (int i = 0; i <items.size() ; i++) {
  77.             if(i % 2 != 0){
  78.                 double price = Double.parseDouble(items.get(i));
  79.                  saveMoney+=price;
  80.                 System.out.printf("%.2f ",price);
  81.             }
  82.         }
  83.         System.out.println();
  84.         System.out.printf("Profit: %.2f%n",profit);
  85.         if(saveMoney >= 150 ){
  86.             System.out.println("Hello, France!");
  87.         }else{
  88.             System.out.println("Time to go.");
  89.         }
  90.  
  91.  
  92.     }
  93.  
  94.     private static List<String> getInput(Scanner scan) {
  95.         String input = scan.nextLine();
  96.         String replace = input.replaceAll("[\\\\|\\- +>]", " ");
  97.         String[] tokens = replace.split("\\s+");
  98.         List<String> result = new ArrayList<>();
  99.  
  100.         for (String currentElement : tokens) {
  101.             result.add(currentElement);
  102.         }
  103.         return result;
  104.  
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement