Advertisement
desislava_topuzakova

03. New House

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