Advertisement
uktcar

03.2.03NewHouse

Mar 17th, 2023
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ex03NewHouse {
  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.         double totalPrice = 0.0;
  12.  
  13.         if (flowerType.equals("Roses")) {
  14.             totalPrice = flowerCount * 5.0;
  15.             if (flowerCount > 80) {
  16.                 totalPrice *= 0.9;
  17.             }
  18.         } else if (flowerType.equals("Dahlias")) {
  19.             totalPrice = flowerCount * 3.8;
  20.             if (flowerCount > 90) {
  21.                 totalPrice *= 0.85;
  22.             }
  23.         } else if (flowerType.equals("Tulips")) {
  24.             totalPrice = flowerCount * 2.8;
  25.             if (flowerCount > 80) {
  26.                 totalPrice *= 0.85;
  27.             }
  28.         } else if (flowerType.equals("Narcissus")) {
  29.             totalPrice = flowerCount * 3.0;
  30.             if (flowerCount < 120) {
  31.                 totalPrice *= 1.15;
  32.             }
  33.         } else if (flowerType.equals("Gladiolus")) {
  34.             totalPrice = flowerCount * 2.5;
  35.             if (flowerCount < 80) {
  36.                 totalPrice *= 1.20;
  37.             }
  38.         }
  39.  
  40.         double difference = Math.abs(budget - totalPrice);
  41.  
  42.         if (budget >= totalPrice) {
  43.             System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.",
  44.                     flowerCount, flowerType, difference);
  45.         } else {
  46.             System.out.printf("Not enough money, you need %.2f leva more.", difference);
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement