Advertisement
Guest User

Untitled

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