Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class While {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double budget = Double.parseDouble(scanner.nextLine());
  8. String command = scanner.nextLine();
  9. double price = 0;
  10. double moneySpent = 0;
  11. int n = 0;
  12. while(!command.equals("Finish")){
  13. n++;
  14. switch(command){
  15. case "Star":
  16. price = 5.69;
  17. break;
  18. case "Angel":
  19. price = 8.49;
  20. break;
  21. case "Lights":
  22. price = 11.20;
  23. break;
  24. case "Wreath":
  25. price = 15.50;
  26. break;
  27. case "Candle":
  28. price = 3.59;
  29. break;
  30. }
  31. if(n%3==0){
  32. price = price * 0.7;
  33. }
  34. if(budget<price){
  35. break;
  36. }
  37. moneySpent += price;
  38. budget -=price;
  39. command = scanner.nextLine();
  40.  
  41. }
  42. if(budget<price){
  43. n--;
  44. System.out.printf("Not enough money! You need %.2flv more.%n", price-budget);
  45.  
  46. }else{
  47. System.out.printf("Congratulations! You bought everything!%n");
  48.  
  49. }
  50. System.out.printf("%d items -> %.2flv spent.",n,moneySpent);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement