SophiYo

02

Mar 12th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package O1ExamMid10MArch;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. public class Problem02 {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader =
  12.             new BufferedReader(
  13.                 new InputStreamReader(
  14.                     System.in
  15.                 )
  16.             );
  17.  
  18.        String input = reader.readLine();
  19.        double budget = Double.parseDouble(reader.readLine());
  20.        String[] itemsString = input.split("\\|");
  21.  
  22.         double addThis = 0;
  23.        double profit = 0.0;
  24.        List<String> items = new ArrayList<>();
  25.         for (int i = 0; i < itemsString.length; i++) {
  26.             String[] token = itemsString[i].split("->") ;
  27.  
  28.             String item = token[0].toLowerCase();
  29.  
  30.             double priceItem = Double.parseDouble(token[1]);
  31.  
  32.             switch (item) {
  33.                 case "clothes" :
  34.                     if (priceItem<=50.00 && priceItem <= budget) {
  35.                         budget -= priceItem;
  36.                         profit += priceItem*1.4 - priceItem;
  37.                         addThis += priceItem*1.4;
  38.                         items.add(String.format("%.2f",priceItem*1.4 ));
  39.                     }
  40.                     break;
  41.  
  42.                 case "shoes" :
  43.                     if (priceItem<=35.00 && priceItem <= budget) {
  44.                         budget -= priceItem;
  45.                         profit += priceItem*1.4- priceItem;
  46.                         addThis += priceItem*1.4;
  47.                         items.add(String.format("%.2f",priceItem*1.4 ));
  48.                     }
  49.                     break;
  50.  
  51.                 case "accessories" :
  52.                     if (priceItem<=20.50 && priceItem <= budget) {
  53.                         budget -= priceItem;
  54.                         profit += priceItem*1.4- priceItem;
  55.                         addThis += priceItem*1.4;
  56.                         items.add(String.format("%.2f",priceItem*1.4 ));
  57.                     }
  58.                     break;
  59.                     default:
  60.                         break;
  61.             }
  62.  
  63.         }
  64.  
  65.         System.out.println(items
  66.                 .toString()
  67.                 .replaceAll("[\\[|,\\]]", "")
  68.                 .trim());
  69.         System.out.println(String.format("Profit: %.2f", profit));
  70.  
  71.         if (budget + addThis>= 150) {
  72.  
  73.             System.out.println("Hello, France!");
  74.         } else {
  75.  
  76.             System.out.println("Time to go.");
  77.  
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment