Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WeddingDecoration {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double balloonPrice = 0.1;
  8.         double flowerPrice = 1.5;
  9.         double candlePrice = 0.5;
  10.         int ribbonPriceForMeter = 2;
  11.  
  12.         double budget = Double.parseDouble(scanner.nextLine());
  13.         String input = scanner.nextLine();
  14.  
  15.         double flowersSum = 0.0;
  16.         int flowersCount = 0;
  17.         double balloonsSum = 0.0;
  18.         int balloonsCount = 0;
  19.         double candlesSum = 0.0;
  20.         int candlesCount = 0;
  21.         double ribbonsSum = 0.0;
  22.         int ribbonsCount = 0;
  23.         double spendMoney = 0.0;
  24.  
  25.         while (!input.equals("stop")) {
  26.             int countStock = Integer.parseInt(scanner.nextLine());
  27.  
  28.             if (input.equals("balloons")) {
  29.                 balloonsSum = countStock * balloonPrice;
  30.                 budget -= balloonsSum;
  31.                 balloonsCount += countStock;
  32.                 spendMoney += balloonsSum;
  33.  
  34.             } else if (input.equals("flowers")) {
  35.                 flowersSum = countStock * flowerPrice;
  36.                 budget -= flowersSum;
  37.                 flowersCount += countStock;
  38.                 spendMoney += flowersSum;
  39.  
  40.             } else if (input.equals("candles")) {
  41.                 candlesSum = countStock * candlePrice;
  42.                 budget -= candlesSum;
  43.                 candlesCount += countStock;
  44.                 spendMoney += candlesSum;
  45.  
  46.             } else if (input.equals("ribbon")) {
  47.                 ribbonsSum = countStock * ribbonPriceForMeter;
  48.                 budget -= ribbonsSum;
  49.                 ribbonsCount += countStock;
  50.                 spendMoney += ribbonsSum;
  51.  
  52.             }
  53.             if (budget <= 0) {
  54.                 System.out.println("All money is spent!");
  55.                 break;
  56.             }
  57.  
  58.             input = scanner.nextLine();
  59.         }
  60.         if (input.equals("stop")) {
  61.             System.out.printf("Spend money: %.2f%n", spendMoney);
  62.             System.out.printf("Money left: %.2f%n", budget);
  63.         }
  64.  
  65.         System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.%n",
  66.                 balloonsCount, ribbonsCount, flowersCount, candlesCount);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement