Advertisement
silviasj

new house

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