Groney

WeddingDecoration

Dec 18th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. package SelfTestExams.NovemberExam2018Part2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WeddingDec {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         double budget = Double.parseDouble(scan.nextLine());
  10.         String stock = scan.nextLine();
  11.  
  12.         double spent = 0;
  13.         double price = 0;
  14.  
  15.         int ballCount = 0;
  16.         int flowCount = 0;
  17.         int candCount = 0;
  18.         int ribCount = 0;
  19.  
  20.         while (!"stop".equals(stock)) {
  21.             int num = Integer.parseInt(scan.nextLine());
  22.  
  23.             if (spent > budget) {
  24.                 System.out.println("All money is spent!");
  25.                 break;
  26.             }
  27.  
  28.             switch (stock) {
  29.                 case "balloons":
  30.                     price = 0.1 * num;
  31.                     ballCount += num;
  32.                     break;
  33.                 case "flowers":
  34.                     price = 1.5 * num;
  35.                     flowCount += num;
  36.                     break;
  37.                 case "candles":
  38.                     price = 0.5 * num;
  39.                     candCount += num;
  40.                     break;
  41.                 case "ribbon":
  42.                     price = 2 * num;
  43.                     ribCount += num;
  44.                     break;
  45.             }
  46.  
  47.             spent += price;
  48.  
  49.             if (spent >= budget) {
  50.                 System.out.println("All money is spent!");
  51.                 break;
  52.             }
  53.  
  54.             stock = scan.nextLine();
  55.         }
  56.  
  57.         if (budget > spent) {
  58.             System.out.printf("Spend money: %.2f\n", spent);
  59.             System.out.printf("Money left: %.2f\n", Math.abs(budget - spent));
  60.         }
  61.  
  62.         System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", ballCount, ribCount, flowCount, candCount);
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment