Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package November2018;
- import java.util.Scanner;
- public class O04WeddingDecoration {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- double priceBall = 0.1;
- double priceFl = 1.5;
- double priceCand = 0.5;
- double priceRib = 2;
- String command = scanner.nextLine();
- double total = 0;
- int balloons = 0;
- int flowers = 0;
- int candles = 0;
- int ribbon = 0;
- while (!command.equalsIgnoreCase("stop")) {
- String type = command;
- command = scanner.nextLine();
- int counter = Integer.parseInt(command);
- if (type.equalsIgnoreCase("balloons")) {
- balloons += counter;
- total += counter* priceBall;
- } else if (type.equalsIgnoreCase("flowers")) {
- flowers += counter;
- total += counter*priceFl;
- } else if (type.equalsIgnoreCase("candles")) {
- candles += counter;
- total += counter*priceCand;
- } else if (type.equalsIgnoreCase("ribbon")) {
- ribbon += counter;
- total += counter*priceRib;
- }
- 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.",balloons, ribbon, flowers , candles);
- } 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.",balloons, ribbon, flowers , candles); }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment