Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double budget = Double.parseDouble(scanner.nextLine());
- String command = "";
- String products = scanner.nextLine();
- double price = 0.0;
- int counter = 1;
- while (command.equals("Finish" ) || budget < price) {
- switch (products) {
- case "Star":
- price = 5.69;
- budget = budget - price;
- break;
- case "Angel":
- price = 8.49;
- budget = budget - price;
- break;
- case "Lights":
- price = 11.20;
- budget = budget - price;
- break;
- case "Wreath":
- price = 15.50;
- budget = budget - price;
- break;
- case "Candle":
- price = 3.59;
- budget = budget - price;
- break;
- }
- counter++;
- if (counter == 3) {
- price = price - (price * 0.3);
- }
- }
- double needMoney = Math.abs(budget - price);
- if (command.equals("Finish")) {
- System.out.println("Congratulations! You bought everything!" );
- System.out.printf(" %d items -> %.2f lv spent.", counter, needMoney);
- }
- if (budget < price) {
- System.out.printf("Not enough money! You need %.2f lv more.", needMoney);
- System.out.printf(" %d items -> %.2f lv spent.", counter, needMoney);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement