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