SophiYo

Exam/ ex04/ WeddingDeocration

Dec 2nd, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.97 KB | None | 0 0
  1. package November2018;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O04WeddingDecoration {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         double budget = Double.parseDouble(scanner.nextLine());
  9.         double priceBall = 0.1;
  10.         double priceFl = 1.5;
  11.         double priceCand = 0.5;
  12.         double priceRib = 2;
  13.         String command = scanner.nextLine();
  14.         double total = 0;
  15.         int balloons = 0;
  16.         int flowers = 0;
  17.         int candles = 0;
  18.         int ribbon = 0;
  19.  
  20.         while (!command.equalsIgnoreCase("stop")) {
  21.             String type = command;
  22.             command = scanner.nextLine();
  23.             int counter = Integer.parseInt(command);
  24.  
  25.             if (type.equalsIgnoreCase("balloons")) {
  26.                 balloons += counter;
  27.                 total += counter* priceBall;
  28.             } else if (type.equalsIgnoreCase("flowers")) {
  29.                 flowers += counter;
  30.                 total += counter*priceFl;
  31.             } else if (type.equalsIgnoreCase("candles")) {
  32.                 candles += counter;
  33.                 total += counter*priceCand;
  34.             } else if (type.equalsIgnoreCase("ribbon")) {
  35.                 ribbon += counter;
  36.                 total += counter*priceRib;
  37.             }
  38.  
  39.             if (total > budget) {
  40.                 break;
  41.             }
  42.  
  43.             command = scanner.nextLine();
  44.  
  45.         }
  46.  
  47.         if (total > budget) {
  48.             System.out.println("All money is spent!");
  49.             System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.",balloons, ribbon, flowers , candles);
  50.         } else {
  51.             System.out.printf("Spend money: %.2f%n", total);
  52.             System.out.printf("Money left: %.2f%n", (budget - total));
  53.             System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.",balloons, ribbon, flowers , candles);        }
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment