Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exam4New {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- double budgetCounter = 0;
- double balloon = 0.1;
- double flower = 1.5;
- double candle = 0.5;
- double ribbon = 2;
- double moneyLeft = 0;
- double spendMoney = 0;
- int balloonCounter = 0;
- int flowerCounter = 0;
- int candleCounter = 0;
- int ribbonCounter = 0;
- String command = scanner.nextLine();
- while (!command.equalsIgnoreCase("stop")) {
- String decoration = command;
- command = scanner.nextLine();
- int decorationNumber = Integer.parseInt(command);
- switch (decoration) {
- case "balloons":
- budgetCounter += (decorationNumber * balloon);
- balloonCounter += decorationNumber;
- break;
- case "flowers":
- budgetCounter += (decorationNumber * flower);
- flowerCounter += decorationNumber;
- break;
- case "candles":
- budgetCounter += (decorationNumber * candle);
- candleCounter += decorationNumber;
- break;
- case "ribbon":
- budgetCounter += (decorationNumber * ribbon);
- ribbonCounter += decorationNumber;
- break;
- }
- if (budgetCounter >= budget) {
- System.out.println("All money is spent!");
- break;
- }
- command = scanner.nextLine();
- }
- if (budget > budgetCounter) {
- moneyLeft = budget - budgetCounter;
- spendMoney = budget - moneyLeft;
- System.out.printf("Spend money: %.2f\nMoney left: %.2f\n", spendMoney, moneyLeft);
- }
- System.out.printf("Purchased decoration is %d balloons, %d m ribbon, %d flowers and %d candles.",
- balloonCounter, ribbonCounter, flowerCounter, candleCounter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment