Advertisement
desislava_topuzakova

03. New House

Oct 18th, 2020
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //1.ВХОД:
  7.         // вид на цветята ("Roses", "Dahlias", "Tulips", "Narcissus", "Gladiolus")
  8.         // брой на цветята - int
  9.         // бюджет - int
  10.         //2. ед.цена за цвете -> зависи от вида
  11.         //3. намираме крайната цена = бр. цветя * ед.цена за цвете
  12.         //4. проверка за отстъпки
  13.         //5. проверка дали стига бюджетът
  14.         String flowerType = scanner.nextLine();
  15.         int flowerCount = Integer.parseInt(scanner.nextLine());
  16.         int budget = Integer.parseInt(scanner.nextLine());
  17.  
  18.         //•   Ако Нели Купи по-малко от 80 Гладиоли - цената се оскъпява с 20%
  19.         double price = 0; //крайната цена
  20.         switch (flowerType) {
  21.             case "Roses":
  22.                 price = flowerCount * 5;
  23.                 if (flowerCount > 80) {
  24.                     price = price - 0.10 * price; //0.9 * price
  25.                 }
  26.                 break;
  27.             case "Dahlias":
  28.                 price = flowerCount * 3.80;
  29.                 if (flowerCount > 90) {
  30.                     price = price - 0.15 * price; //0.85 * price
  31.                 }
  32.                 break;
  33.             case "Tulips":
  34.                 price = flowerCount * 2.80;
  35.                 if (flowerCount > 80) {
  36.                     price = price - 0.15 * price;
  37.                 }
  38.                 break;
  39.             case "Narcissus":
  40.                 price = flowerCount * 3;
  41.                 if (flowerCount < 120) {
  42.                     price = price + 0.15 * price; //1.15 * price
  43.                 }
  44.                 break;
  45.             case "Gladiolus":
  46.                 price = flowerCount * 2.50;
  47.                 if (flowerCount < 80) {
  48.                     price = price + 0.2 * price; //1.2 * price
  49.                 }
  50.                 break;
  51.         }
  52.  
  53.         //колко е крайната сметка за плащане
  54.         //достатъчен бюджет
  55.         if (budget >= price) {
  56.             double leftMoney = budget - price;
  57.             System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.", flowerCount, flowerType, leftMoney);
  58.         } else {
  59.             //не е достатъчен
  60.             double needMoney = price - budget;
  61.             System.out.printf("Not enough money, you need %.2f leva more.", needMoney);
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement