Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- double budget = Double.parseDouble(br.readLine());
- String product = br.readLine();
- double spentMoney = 0;
- int productsCount = 0;
- int boughtProductsCount = 0;
- while (!product.equals("Finish"))
- {
- double currentPrice = 0;
- switch (product)
- {
- case "Star": currentPrice = 5.69; break;
- case "Angel": currentPrice = 8.49; break;
- case "Lights": currentPrice = 11.20; break;
- case "Wreath": currentPrice = 15.50; break;
- case "Candle": currentPrice = 3.59; break;
- }
- if (currentPrice != 0)
- {
- ++productsCount;
- if (productsCount % 3 == 0)
- {
- currentPrice *= 0.70;
- }
- budget -= currentPrice;
- if (budget < 0)
- {
- break;
- }
- spentMoney += currentPrice;
- ++boughtProductsCount;
- }
- product = br.readLine();
- }
- if (budget < 0)
- {
- System.out.println(String.format("Not enough money! You need %.2flv more.", Math.abs(budget)));
- }
- else
- {
- System.out.println("Congratulations! You bought everything!");
- }
- System.out.println(String.format("%d items -> %.2flv spent.", boughtProductsCount, spentMoney));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement