Advertisement
Deiancom

New House

Jun 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class NewHouse {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String flowersType = scanner.nextLine();
  9.         int flowersCount = Integer.parseInt(scanner.nextLine());
  10.         int budgetForFlowers = Integer.parseInt(scanner.nextLine());
  11.  
  12.         double rosePrice = 5.0;
  13.         double dahliasPrice = 3.8;
  14.         double tulipsPrice = 2.8;
  15.         double narcissusPrice = 3.0;
  16.         double gladiolusPrice = 2.5;
  17.         double price = 0;
  18.         switch (flowersType) {
  19.             case  "roses":
  20.                 price = rosePrice * flowersCount;
  21.                 break;
  22.             case  "dahlias":
  23.                 price = dahliasPrice * flowersCount;
  24.                 break;
  25.             case  "tulips":
  26.                 price = tulipsPrice * flowersCount;
  27.                 break;
  28.             case  "narcissus":
  29.                 price = narcissusPrice * flowersCount;
  30.                 break;
  31.             case  "gladiolus":
  32.                 price = gladiolusPrice * flowersCount;
  33.                 break;
  34.         }
  35.         double finalPrice = 0;
  36.         if (flowersType.equals("roses") && flowersCount > 80 ) {
  37.             finalPrice = price - (price * 0.10);
  38.         }else if (flowersType.equals("dahlias") && flowersCount > 90 ) {
  39.             finalPrice = price - (price * 0.15);
  40.         }else if (flowersType.equals("tulips") && flowersCount > 80) {
  41.             finalPrice = price - (price * 0.15);
  42.         }else if (flowersType.equals("narcissus") && flowersCount < 120 ) {
  43.             finalPrice = price + (price * 0.15);
  44.         }else if (flowersType.equals("gladiolus") && flowersCount < 80 ) {
  45.             finalPrice = price + (price * 0.20);
  46.         }
  47.         if (budgetForFlowers >= finalPrice) {
  48.             System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.",
  49.                     flowersCount,flowersType,budgetForFlowers - finalPrice);
  50.         }else if (finalPrice > budgetForFlowers){
  51.             System.out.printf("Not enough money, you need %.2f leva more",finalPrice - budgetForFlowers);
  52.         }
  53.  
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement