Lyubohd

Untitled

Jun 5th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Test2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         String stock = scanner.nextLine();
  9.         int countBalloons = 0;
  10.         int countFlowers = 0;
  11.         int countCandles = 0;
  12.         int countRibbon = 0;
  13.         double allSpendMoney = 0;
  14.  
  15.         while (!"stop".equals(stock)) {
  16.             int countStock = Integer.parseInt(scanner.nextLine());
  17.  
  18.             if ("balloons".equals(stock)) {
  19.                 countBalloons += countStock;
  20.                 allSpendMoney += countStock * 0.1;
  21.             } else if ("flowers".equals(stock)) {
  22.                 countFlowers += countStock;
  23.                 allSpendMoney += countStock * 1.5;
  24.             } else if ("candles".equals(stock)) {
  25.                 countCandles += countStock;
  26.                 allSpendMoney += countStock * 0.5;
  27.             } else {
  28.                 countRibbon += countStock;
  29.                 allSpendMoney += countStock * 2;
  30.             }
  31.  
  32.             if (allSpendMoney > budget) {
  33.                 System.out.println("All money is spent!");
  34.                 break;
  35.             }
  36.  
  37.             stock = scanner.nextLine();
  38.         }
  39.  
  40.         if ("stop".equals(stock)) {
  41.             System.out.printf("Spend money: %.2f%n", allSpendMoney);
  42.             System.out.printf("Money left: %.2f%n", budget - allSpendMoney);
  43.         }
  44.         System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", countBalloons, countRibbon, countFlowers, countCandles);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment