Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Decoration {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- boolean stopped = false;
- double budget = Double.parseDouble(scanner.nextLine());
- double priceBalloonsTotal = 0;
- double priceFlowersTotal = 0;
- double priceCandlesTotal = 0;
- double priceRibbonsTotal = 0;
- int totalBalloonsCount = 0;
- int totalCandlesCount = 0;
- int totalFlowersCount = 0;
- int totalRibbonsMeters = 0;
- while (budget > 0) {
- String command = scanner.nextLine();
- if (command.equals("balloons")) {
- int balloonsCount = Integer.parseInt(scanner.nextLine());
- totalBalloonsCount += balloonsCount;
- priceBalloonsTotal += (0.1 * balloonsCount);
- budget -= (0.1 * balloonsCount);
- } else if (command.equals("flowers")) {
- int flowersCount = Integer.parseInt(scanner.nextLine());
- totalFlowersCount += flowersCount;
- priceFlowersTotal += (1.5 * flowersCount);
- budget -= (1.5 * flowersCount);
- } else if (command.equals("candles")) {
- int candlesCount = Integer.parseInt(scanner.nextLine());
- totalCandlesCount += candlesCount;
- priceCandlesTotal += (0.5 * candlesCount);
- budget -= (0.5 * candlesCount);
- }else if (command.equals("ribbon")) {
- int ribbonMeters = Integer.parseInt(scanner.nextLine());
- totalRibbonsMeters += ribbonMeters;
- priceRibbonsTotal += (2 * ribbonMeters);
- budget -= (2 * ribbonMeters);
- }
- if (command.equals("stop")) {
- System.out.printf("Spend money: %.2f\n", priceBalloonsTotal + priceCandlesTotal + priceFlowersTotal + priceRibbonsTotal);
- System.out.printf("Money left: %.2f\n", budget);
- stopped = true;
- break;
- }
- }
- if(!stopped)
- {
- System.out.println("All money is spent!");
- }
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", totalBalloonsCount,
- totalRibbonsMeters, totalFlowersCount, totalCandlesCount);
- stopped = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement