Advertisement
GabrielHr00

03. New House

May 28th, 2023
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package S3_ConditionalStatementsAdvanced;
  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 flowerType = scanner.nextLine();
  9.         int count = Integer.parseInt(scanner.nextLine());
  10.         int budget = Integer.parseInt(scanner.nextLine());
  11.  
  12.         double finalPrice = 0.0;
  13.         switch (flowerType) {
  14.             case "Roses":
  15.                 finalPrice = 5.0 * count;
  16.  
  17.                 if(count > 80) {
  18.                     //finalPrice = finalPrice - (finalPrice * 0.10);
  19.                     finalPrice = finalPrice * 0.90;
  20.                 }
  21.                 break;
  22.             case "Dahlias":
  23.                 finalPrice = 3.80 * count;
  24.  
  25.                 if(count > 90) {
  26.                     //finalPrice = finalPrice - (finalPrice * 0.15);
  27.                     finalPrice = finalPrice * 0.85;
  28.                 }
  29.                 break;
  30.             case "Tulips":
  31.                 finalPrice = 2.80 * count;
  32.  
  33.                 if(count > 80) {
  34.                     //finalPrice = finalPrice - (finalPrice * 0.15);
  35.                     finalPrice = finalPrice * 0.85;
  36.                 }
  37.                 break;
  38.             case "Narcissus":
  39.                 finalPrice = 3.0 * count;
  40.  
  41.                 if (count < 120) {
  42.                     //finalPrice = finalPrice + (finalPrice * 0.15);
  43.                     finalPrice = finalPrice * 1.15;
  44.                 }
  45.                 break;
  46.             case "Gladiolus":
  47.                 finalPrice = 2.50 * count;
  48.  
  49.                 if (count < 80) {
  50.                     //finalPrice = finalPrice + (finalPrice * 0.20);
  51.                     finalPrice = finalPrice * 1.20;
  52.                 }
  53.                 break;
  54.         }
  55.  
  56.  
  57.         double diff = Math.abs(budget - finalPrice);
  58.         if(budget >= finalPrice) {
  59.             System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.", count, flowerType, diff);
  60.         } else {
  61.             System.out.printf("Not enough money, you need %.2f leva more.", diff);
  62.         }
  63.  
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement