Helena12

WeddingDecoration

Nov 28th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exam4New {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double budget = Double.parseDouble(scanner.nextLine());
  8.         double budgetCounter = 0;
  9.  
  10.         double balloon = 0.1;
  11.         double flower = 1.5;
  12.         double candle = 0.5;
  13.         double ribbon = 2;
  14.  
  15.         double moneyLeft = 0;
  16.         double spendMoney = 0;
  17.  
  18.         int balloonCounter = 0;
  19.         int flowerCounter = 0;
  20.         int candleCounter = 0;
  21.         int ribbonCounter = 0;
  22.  
  23.         String command = scanner.nextLine();
  24.  
  25.         while (!command.equalsIgnoreCase("stop")) {
  26.  
  27.             String decoration = command;
  28.             command = scanner.nextLine();
  29.             int decorationNumber = Integer.parseInt(command);
  30.  
  31.             switch (decoration) {
  32.                 case "balloons":
  33.                     budgetCounter += (decorationNumber * balloon);
  34.                     balloonCounter += decorationNumber;
  35.                     break;
  36.                 case "flowers":
  37.                     budgetCounter += (decorationNumber * flower);
  38.                     flowerCounter += decorationNumber;
  39.                     break;
  40.                 case "candles":
  41.                     budgetCounter += (decorationNumber * candle);
  42.                     candleCounter += decorationNumber;
  43.  
  44.                     break;
  45.                 case "ribbon":
  46.                     budgetCounter += (decorationNumber * ribbon);
  47.                     ribbonCounter += decorationNumber;
  48.                     break;
  49.             }
  50.  
  51.             if (budgetCounter >= budget) {
  52.                 System.out.println("All money is spent!");
  53.                 break;
  54.             }
  55.  
  56.             command = scanner.nextLine();
  57.         }
  58.         if (budget > budgetCounter) {
  59.             moneyLeft = budget - budgetCounter;
  60.             spendMoney = budget - moneyLeft;
  61.  
  62.             System.out.printf("Spend money: %.2f\nMoney left: %.2f\n", spendMoney, moneyLeft);
  63.         }
  64.  
  65.         System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.",
  66.                 balloonCounter, ribbonCounter, flowerCounter, candleCounter);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment