Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WeddingDecoration {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double balloonPrice = 0.1;
- double flowerPrice = 1.5;
- double candlePrice = 0.5;
- int ribbonPriceForMeter = 2;
- double budget = Double.parseDouble(scanner.nextLine());
- String input = scanner.nextLine();
- double flowersSum = 0.0;
- int flowersCount = 0;
- double balloonsSum = 0.0;
- int balloonsCount = 0;
- double candlesSum = 0.0;
- int candlesCount = 0;
- double ribbonsSum = 0.0;
- int ribbonsCount = 0;
- double spendMoney = 0.0;
- while (!input.equals("stop")) {
- int countStock = Integer.parseInt(scanner.nextLine());
- if (input.equals("balloons")) {
- balloonsSum = countStock * balloonPrice;
- budget -= balloonsSum;
- balloonsCount += countStock;
- spendMoney += balloonsSum;
- } else if (input.equals("flowers")) {
- flowersSum = countStock * flowerPrice;
- budget -= flowersSum;
- flowersCount += countStock;
- spendMoney += flowersSum;
- } else if (input.equals("candles")) {
- candlesSum = countStock * candlePrice;
- budget -= candlesSum;
- candlesCount += countStock;
- spendMoney += candlesSum;
- } else if (input.equals("ribbon")) {
- ribbonsSum = countStock * ribbonPriceForMeter;
- budget -= ribbonsSum;
- ribbonsCount += countStock;
- spendMoney += ribbonsSum;
- }
- if (budget <= 0) {
- System.out.println("All money is spent!");
- break;
- }
- input = scanner.nextLine();
- }
- if (input.equals("stop")) {
- System.out.printf("Spend money: %.2f%n", spendMoney);
- System.out.printf("Money left: %.2f%n", budget);
- }
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.%n",
- balloonsCount, ribbonsCount, flowersCount, candlesCount);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement