Advertisement
Krassi_Daskalova

NewHouse

Feb 3rd, 2019
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NewHouse {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. String flower = scanner.nextLine();
  7. int flowerNumber = Integer.parseInt(scanner.nextLine());
  8. int budget = Integer.parseInt(scanner.nextLine());
  9.  
  10. double price = 0;
  11.  
  12. switch (flower) {
  13. case "Roses":
  14. price = 5;
  15. break;
  16. case "Dahlias":
  17. price = 3.8;
  18. break;
  19. case "Tulips":
  20. price = 2.8;
  21. break;
  22. case "Narcissus":
  23. price = 3;
  24. break;
  25. case "Gladiolus":
  26. price = 2.5;
  27. break;
  28. }
  29. double totalPrice = flowerNumber * price;
  30. if (flower.equals("Roses") && flowerNumber > 80) {
  31. totalPrice = totalPrice * 0.9;
  32. } else if (flower.equals("Dahlias") && flowerNumber > 90) {
  33. totalPrice = totalPrice * 0.85;
  34. } else if (flower.equals("Tulips") && flowerNumber > 80) {
  35. totalPrice = totalPrice * 0.85;
  36. } else if (flower.equals("Narcissus") && flowerNumber < 120) {
  37. totalPrice = totalPrice * 1.15;
  38. } else if (flower.equals("Gladiolus") && flowerNumber < 80) {
  39. totalPrice = totalPrice * 1.20;
  40. }
  41. double extraMoney = budget - totalPrice;
  42. if (extraMoney >= 0) {
  43. System.out.printf("Hey, you have a great garden with %d %s and %.2f leva left.", flowerNumber, flower, extraMoney);
  44. }else {
  45. System.out.printf("Not enough money, you need %.2f leva more.", Math.abs(extraMoney));
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement