Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         double budget = Double.parseDouble(scanner.nextLine());
  11.         String command = "";
  12.         String products = scanner.nextLine();
  13.  
  14.  
  15.         double price = 0.0;
  16.         int counter = 1;
  17.  
  18.         while (command.equals("Finish" ) || budget < price) {
  19.  
  20.             switch (products) {
  21.                 case "Star":
  22.                     price = 5.69;
  23.                     budget = budget - price;
  24.                     break;
  25.                 case "Angel":
  26.                     price = 8.49;
  27.                     budget = budget - price;
  28.                     break;
  29.                 case "Lights":
  30.                     price = 11.20;
  31.                     budget = budget - price;
  32.                     break;
  33.                 case "Wreath":
  34.                     price = 15.50;
  35.                     budget = budget - price;
  36.                     break;
  37.                 case "Candle":
  38.                     price = 3.59;
  39.                     budget = budget - price;
  40.                     break;
  41.             }
  42.  
  43.             counter++;
  44.  
  45.             if (counter == 3) {
  46.                 price = price - (price * 0.3);
  47.             }
  48.  
  49.         }
  50.  
  51.         double needMoney = Math.abs(budget - price);
  52.  
  53.         if (command.equals("Finish")) {
  54.             System.out.println("Congratulations! You bought everything!" );
  55.             System.out.printf(" %d items -> %.2f lv spent.", counter, needMoney);
  56.         }
  57.         if (budget < price) {
  58.             System.out.printf("Not enough money! You need %.2f lv more.", needMoney);
  59.             System.out.printf(" %d items -> %.2f lv spent.", counter, needMoney);
  60.  
  61.  
  62.         }
  63.  
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement