Advertisement
Deiancom

Trip Expenses

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