Advertisement
veronikaaa86

03. New House

Jan 23rd, 2022
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. package advancedConditionalStatements;
  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 = countFlowers * 5.0;
  17. if (countFlowers > 80) {
  18. totalPrice = totalPrice - (totalPrice * 0.10);
  19. //totalPrice = totalPrice * 0.90;
  20. }
  21. break;
  22. case "Dahlias":
  23. totalPrice = countFlowers * 3.80;
  24. if (countFlowers > 90){
  25. totalPrice = totalPrice - (totalPrice * 0.15);
  26. //totalPrice = totalPrice * 0.85;
  27. }
  28. break;
  29. case "Tulips":
  30. totalPrice = countFlowers * 2.80;
  31. if (countFlowers > 80) {
  32. totalPrice = totalPrice - (totalPrice * 0.15);
  33. }
  34. break;
  35. case "Narcissus":
  36. totalPrice = countFlowers * 3.0;
  37. if (countFlowers < 120) {
  38. totalPrice = totalPrice + (totalPrice * 0.15);
  39. //totalPrice = totalPrice * 1.15;
  40. }
  41. break;
  42. case "Gladiolus":
  43. totalPrice = countFlowers * 2.50;
  44. if (countFlowers < 80) {
  45. totalPrice = totalPrice + (totalPrice * 0.20);
  46. }
  47. break;
  48. }
  49.  
  50. double diff = Math.abs(budget - totalPrice);
  51. if (budget >= totalPrice) {
  52. System.out.printf
  53. ("Hey, you have a great garden with %d %s and %.2f leva left.",
  54. countFlowers, typeFlower, diff);
  55. } else {
  56. System.out.printf("Not enough money, you need %.2f leva more.",
  57. diff);
  58. }
  59. }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement