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