Guest User

Untitled

a guest
Jun 5th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class HelloFrance {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.        String[] items = scanner.nextLine().split("[|]");
  8.        double budget = Double.parseDouble(scanner.nextLine());
  9.  
  10.        double clothesMaxPrice = 50;
  11.        double shoesMaxPrice = 35;
  12.        double accessoriesMaxPrice = 20.50;
  13.        double neededMoney = 150;
  14.        double newPrice = 0;
  15.        double sumOfPrices = 0;
  16.        double sumOfNewPrices = 0;
  17.        double profit = 0;
  18.        boolean isBought = true;
  19.  
  20.  
  21.         for (int i = 0; i < items.length ; i++) {
  22.            String[] itemType = items[i].split("->");
  23.  
  24.             String type = itemType[0];
  25.             double price = Double.parseDouble(itemType[1]);
  26.  
  27.             if ("Clothes".equals(type)){
  28.                 if (price <= clothesMaxPrice && price <= budget){
  29.                     sumOfPrices += price;
  30.                     budget -= price;
  31.                     newPrice = price * 1.40;
  32.                     sumOfNewPrices += newPrice;
  33.                     isBought = true;
  34.  
  35.                 } else {
  36.                     isBought = false;
  37.                     //break;
  38.                 }
  39.             } else if ("Shoes".equals(type)){
  40.                 if (price <= shoesMaxPrice && price <= budget){
  41.                     sumOfPrices += price;
  42.                     budget -= price;
  43.                     newPrice = price * 1.40;
  44.                     sumOfNewPrices += newPrice;
  45.                     isBought = true;
  46.                 } else {
  47.                     isBought = false;
  48.                     //break;
  49.                 }
  50.             } else if ("Accessories".equals(type)){
  51.                 if (price <= accessoriesMaxPrice && price <= budget){
  52.                     sumOfPrices += price;
  53.                     budget -= price;
  54.                     newPrice = price * 1.40;
  55.                     sumOfNewPrices += newPrice;
  56.                     isBought = true;
  57.                 } else {
  58.                     isBought = false;
  59.                    // break;
  60.                 }
  61.             }
  62.  
  63.             if (isBought) {
  64.                 System.out.printf("%.2f ", newPrice);
  65.             }
  66.  
  67.         }
  68.         profit = sumOfNewPrices - sumOfPrices;
  69.  
  70.         System.out.println();
  71.         System.out.printf("Profit: %.2f%n", profit);
  72.  
  73.         if ((sumOfNewPrices + budget) >= neededMoney){
  74.             System.out.println("Hello, France!");
  75.         } else {
  76.             System.out.println("Time to go.");
  77.         }
  78.  
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment