Advertisement
markopizzy

Untitled

Nov 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Tourist_shop {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double budget = Double.parseDouble(scanner.nextLine());
  8. String productName = scanner.nextLine();
  9. int productCount = 0;
  10. boolean isFinished = false;
  11. boolean isBigger = false;
  12. double priceTotal = 0;
  13. double priceNeeded = 0;
  14.  
  15. while (!"Stop".equals(productName)) {
  16. double productPrice = Double.parseDouble(scanner.nextLine());
  17.  
  18. if (productPrice > budget) {
  19. priceNeeded = productPrice - budget;
  20. isBigger = true;
  21. break;
  22. }
  23. productCount++;
  24.  
  25. if (productCount > 1 && productCount % 3 == 0) {
  26. productPrice *= 0.50;
  27. }
  28. budget -= productPrice;
  29.  
  30. if (budget <= 0) {
  31. isFinished = true;
  32. break;
  33. }
  34. priceTotal += productPrice;
  35. productName = scanner.nextLine();
  36. }
  37. if (isBigger) {
  38. System.out.println("You don't have enough money!");
  39. System.out.printf("You need %.2f leva!", priceNeeded);
  40. } else {
  41. if (isFinished){
  42. System.out.printf("You bought %d products for %.2f leva.", productCount, priceTotal);
  43. }
  44. else {
  45. System.out.printf("You bought %d products for %.2f leva.", productCount, priceTotal);
  46. }
  47.  
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement