Advertisement
Andreeva-Magdalena97

Wedding Decoration

Mar 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. package WhileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class WeddingDecoration {
  6.     public static void main(String[] args) {
  7.         Scanner s = new Scanner(System.in);
  8.  
  9.         double n = Double.parseDouble(s.nextLine());
  10.         String name = s.nextLine();
  11.         double price = 0;
  12.  
  13.         int bal = 0;
  14.         int fl = 0;
  15.         int cen = 0;
  16.         int rib = 0;
  17.         double budget = 0;
  18.         while(!name.equals("stop")){
  19.  
  20.             int balons = Integer.parseInt(s.nextLine());
  21.  
  22.             if(name.equals("balloons")){
  23.                 price += balons * 0.1;
  24.                 bal += balons;
  25.             }
  26.             if(name.equals("flowers")){
  27.                 price += balons * 1.5;
  28.                 fl += balons;
  29.             }
  30.             if(name.equals("candles")){
  31.                 price += balons * 0.5;
  32.                 cen += balons;
  33.             }
  34.             if(name.equals("ribbon")){
  35.                 price += balons * 2;
  36.                 rib += balons;
  37.             }
  38.  
  39.             budget = n - price;
  40.  
  41.             if(budget <= 0){
  42.                 System.out.printf("All money is spent!%n");
  43.                 break;
  44.             }
  45.             name = s.nextLine();
  46.         }
  47.         if (name.equals("stop")){
  48.             System.out.printf("Spend money: %.2f%n", price);
  49.             System.out.printf("Money left: %.2f%n", n - price);
  50.         }
  51.         System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", bal, rib, fl, cen );
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement