Advertisement
veronikaaa86

03. New House

Nov 14th, 2021
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package exerciseAdvConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03NewHouse {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String typeFlower = scanner.nextLine();
  10. int countFlowers = Integer.parseInt(scanner.nextLine());
  11. int budget = Integer.parseInt(scanner.nextLine());
  12.  
  13. double totalPrice = 0;
  14. switch (typeFlower) {
  15. case "Roses":
  16. totalPrice = 5 * countFlowers;
  17. if (countFlowers > 80) {
  18. totalPrice = totalPrice - (totalPrice * 0.10);
  19. }
  20. break;
  21. case "Dahlias":
  22. totalPrice = 3.80 * countFlowers;
  23. if (countFlowers > 90) {
  24. totalPrice = totalPrice - (totalPrice * 0.15);
  25. }
  26. break;
  27. case "Tulips":
  28. totalPrice = 2.80 * countFlowers;
  29. if (countFlowers > 80) {
  30. totalPrice = totalPrice - (totalPrice * 0.15);
  31. }
  32. break;
  33. case "Narcissus":
  34. totalPrice = 3 * countFlowers;
  35. if (countFlowers < 120) {
  36. totalPrice = totalPrice * 1.15;
  37. }
  38. break;
  39. case "Gladiolus":
  40. totalPrice = 2.50 * countFlowers;
  41. if (countFlowers < 80) {
  42. totalPrice = totalPrice * 1.20;
  43. }
  44. break;
  45.  
  46. }
  47.  
  48. double diff = Math.abs(totalPrice - budget);
  49. if (totalPrice <= budget) {
  50. System.out.printf("Hey, you have a great garden with %d %s " +
  51. "and %.2f leva left.", countFlowers, typeFlower, diff);
  52. } else {
  53. System.out.printf("Not enough money, you need %.2f leva more.", diff);
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement