Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class E04weddingDecoration {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- double balloonsPrice = 0.1;
- double flowersPrice = 1.5;
- double candlesPrice = 0.5;
- double ribbonPrice = 2;
- String command = scanner.nextLine();
- double total = 0;
- int ballonsCount = 0;
- int flowersCount = 0;
- int candlesCount = 0;
- int ribbonMeters = 0;
- while (!(command.equalsIgnoreCase("stop"))) {
- String type = command;
- command = scanner.nextLine();
- int countOfDecoration = Integer.parseInt(command);
- if (type.equalsIgnoreCase("balloons")) {
- ballonsCount += countOfDecoration;
- total += countOfDecoration * balloonsPrice;
- } else if (type.equalsIgnoreCase("flowers")) {
- flowersCount += countOfDecoration;
- total += countOfDecoration * flowersPrice;
- } else if (type.equalsIgnoreCase("candles")) {
- candlesCount += countOfDecoration;
- total += countOfDecoration * candlesPrice;
- } else if (type.equalsIgnoreCase("ribbon")) {
- ribbonMeters += countOfDecoration;
- total += countOfDecoration * ribbonPrice;
- }
- if (total >= budget) {
- break;
- }
- command = scanner.nextLine();
- }
- if (total >= budget) {
- System.out.println("All money is spent!");
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", ballonsCount,ribbonMeters, flowersCount,candlesCount);
- } else {
- System.out.printf("Spend money: %.2f%n", total);
- System.out.printf("Money left: %.2f%n", budget - total);
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.", ballonsCount, ribbonMeters, flowersCount, candlesCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment