Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Exam_trip_expenses {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int days = Integer.parseInt(scanner.nextLine());
- double dayLimit = 60;
- double moneyLeft = 0;
- for (int i = 1; i <= days; i++) {
- String input = scanner.nextLine();
- boolean isReached = false;
- int productsCount = 0;
- double dayLimitPlus = dayLimit + moneyLeft;
- while (!"Day over".equals(input)) {
- double price = Double.parseDouble(input);
- if (price <= dayLimitPlus) {
- dayLimitPlus -= price;
- productsCount++;
- }
- if (dayLimitPlus == 0) {
- isReached = true;
- break;
- }
- input = scanner.nextLine();
- }
- if (isReached) {
- System.out.printf("Daily limit exceeded! You've bought %d products.%n", productsCount);
- } else {
- moneyLeft = dayLimitPlus; // wasn't set!
- System.out.printf("Money left from today: %.2f. You've bought %d products.%n", dayLimitPlus, productsCount);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement