Advertisement
markopizzy

Untitled

Oct 30th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exam_trip_expenses {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int days = Integer.parseInt(scanner.nextLine());
  8. double dayLimit = 60;
  9. double moneyLeft = 0;
  10.  
  11. for (int i = 1; i <= days; i++) {
  12. String input = scanner.nextLine();
  13. boolean isReached = false;
  14. int productsCount = 0;
  15. double dayLimitPlus = dayLimit + moneyLeft;
  16.  
  17. while (!"Day over".equals(input)) {
  18. double price = Double.parseDouble(input);
  19. if (price <= dayLimitPlus) {
  20. dayLimitPlus -= price;
  21. productsCount++;
  22. }
  23. if (dayLimitPlus == 0) {
  24. isReached = true;
  25. break;
  26. }
  27. input = scanner.nextLine();
  28. }
  29. if (isReached) {
  30. System.out.printf("Daily limit exceeded! You've bought %d products.%n", productsCount);
  31. } else {
  32. moneyLeft = dayLimitPlus; // wasn't set!
  33. System.out.printf("Money left from today: %.2f. You've bought %d products.%n", dayLimitPlus, productsCount);
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement