Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 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.  
  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. }else{
  37. n++;
  38. }
  39. moneySpent += price;
  40. budget -=price;
  41. command = scanner.nextLine();
  42.  
  43. }
  44. if(budget<price){
  45. System.out.printf("Not enough money! You need %.2flv more.%n", price-budget);
  46.  
  47. }else{
  48. System.out.printf("Congratulations! You bought everything!%n");
  49.  
  50. }
  51. System.out.printf("%d items -> %.2flv spent.",n,moneySpent);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement