Advertisement
IvaAnd

TouristShop_Online Retake Exam - 2 and 3 May 2019

Mar 26th, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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.  
  7. double budget = Double.parseDouble(scanner.nextLine());
  8. String product = "";
  9. double productPrice = 0;
  10.  
  11. int productCount= 0;
  12. double totalPrice=0;
  13.  
  14.  
  15. while (!product.equals("Stop")){
  16. product = scanner.nextLine();
  17.  
  18. if (product.equals("Stop")) {
  19. System.out.printf("You bought %d products for %.2f leva.", productCount, totalPrice);
  20. break;
  21. }
  22. productPrice = Double.parseDouble(scanner.nextLine());
  23. productCount ++;
  24.  
  25. if (productCount %3==0){
  26. productPrice = productPrice/2;
  27. }
  28.  
  29. totalPrice = totalPrice+productPrice;
  30. budget=budget-productPrice;
  31.  
  32. if (budget<=0){
  33.  
  34. System.out.println("You don't have enough money!");
  35. System.out.printf("You need %.2f leva!", Math.abs(budget));
  36. break;
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement