Advertisement
veronikaaa86

03. New House

Jun 20th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 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 typeFlowers = scanner.nextLine();
  10. int countFlowers = Integer.parseInt(scanner.nextLine());
  11. int budget = Integer.parseInt(scanner.nextLine());
  12.  
  13. double totalSum = 0;
  14. switch (typeFlowers) {
  15. case "Roses":
  16. totalSum = countFlowers * 5;
  17. if (countFlowers > 80) {
  18. totalSum = totalSum * 0.90;
  19. }
  20. break;
  21. case "Dahlias":
  22. totalSum = countFlowers * 3.80;
  23. if (countFlowers > 90) {
  24. totalSum = totalSum * 0.85;
  25. }
  26. break;
  27. case "Tulips":
  28. totalSum = countFlowers * 2.80;
  29. if (countFlowers > 80) {
  30. totalSum = totalSum * 0.85;
  31. }
  32. break;
  33. case "Narcissus":
  34. totalSum = countFlowers * 3;
  35. if (countFlowers < 120) {
  36. totalSum = totalSum * 1.15;
  37. }
  38. break;
  39. case "Gladiolus":
  40. totalSum = countFlowers * 2.5;
  41. if (countFlowers < 80) {
  42. totalSum = totalSum * 1.20;
  43. }
  44. break;
  45. }
  46.  
  47. double diff = Math.abs(budget - totalSum);
  48. if (budget >= totalSum) {
  49. System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.",
  50. countFlowers, typeFlowers, diff);
  51. } else {
  52. System.out.printf("Not enough money, you need %.2f leva more.", diff);
  53. }
  54. }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement