Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Demo {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double budget = Double.parseDouble(scanner.nextLine());
  8.  
  9. String product = scanner.nextLine();
  10.  
  11.  
  12. int quantity = 0;
  13. double TotalPrice = 0;
  14. double price = 0;
  15.  
  16. while (!product.equals("Finish")) {
  17.  
  18.  
  19. //Star Angel Lights Wreath Candle
  20. //5.69 8.49 11.20 15.50 3.59
  21.  
  22. if (product.equals("Star")) {
  23. quantity++;
  24. price = 5.69;
  25. if (quantity % 3 == 0) {
  26. price = price * 0.70;
  27. }
  28. TotalPrice += price;
  29. } else if (product.equals("Angel")) {
  30. quantity++;
  31. price = 8.49;
  32. if (quantity % 3 == 0) {
  33. price = price * 0.70;
  34. }
  35. TotalPrice += price;
  36. } else if (product.equals("Lights")) {
  37. quantity++;
  38. price = 11.20;
  39. if (quantity % 3 == 0) {
  40. price = price * 0.70;
  41. }
  42. TotalPrice += price;
  43. } else if (product.equals("Wreath")) {
  44. quantity++;
  45. price = 15.50;
  46. if (quantity % 3 == 0) {
  47. price = price * 0.70;
  48. }
  49. TotalPrice += price;
  50. } else if (product.equals("Candle")) {
  51. quantity++;
  52. price = 3.59;
  53. if (quantity % 3 == 0) {
  54. price = price * 0.70;
  55. }
  56. TotalPrice += price;
  57. }
  58. budget-=price;
  59.  
  60. if (budget <= 0) {
  61. System.out.printf("Not enough money! You need %.2f%n lv more.", Math.abs(TotalPrice - budget));
  62. break;
  63. }
  64. product = scanner.nextLine();
  65. }
  66.  
  67.  
  68. System.out.println("Congratulations! You bought everything!");
  69.  
  70.  
  71. System.out.printf("%d items -> %.2f lv spent.", quantity, TotalPrice);
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement