Advertisement
yovkovbpfps

EXAM 02-03 MAY 2019 Tourist Shop

May 9th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TouristShop {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. double budget = Double.parseDouble(scanner.nextLine());
  7. String input = scanner.nextLine();
  8. double productsCost = 0;
  9. int productsBought = 0;
  10. int productsCount = 0;
  11.  
  12. while (!input.equals("Stop")) {
  13. double price = Double.parseDouble(scanner.nextLine());
  14. productsCount++;
  15.  
  16. if (productsCount % 3 == 0) {
  17. price *= 0.5;
  18. }
  19.  
  20. if (budget < price){
  21. System.out.println("You don't have enough money!");
  22. System.out.printf("You need %.2f leva!", price - budget);
  23. return;
  24. }
  25. productsBought++;
  26. productsCost += price;
  27. budget -= price;
  28. input = scanner.nextLine();
  29. }
  30. System.out.printf("You bought %d products for %.2f leva.", productsBought, productsCost);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement