Advertisement
Guest User

04. New House

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