Advertisement
Deiancom

Trip_Expenses_06

Jul 29th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package EXAM;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Trip_Expenses_06 {
  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.  
  17.             int productsCount = 0;
  18.             String input = scanner.nextLine();
  19.             while (!input.equals("Day over")) {
  20.                 int price = Integer.parseInt(input);
  21.                 if (price <= budget) {
  22.                     budget -= price;
  23.                     productsCount++;
  24.                 }
  25.  
  26.                 if (budget <= 0) {
  27.                     break;
  28.                 }
  29.                 input = scanner.nextLine();
  30.             }
  31.             if (input.equals("Day over")) {
  32.                 System.out.printf("Money left from today: %.2f. You've bought %d products.%n",budget,productsCount);
  33.                 budget = budget + 60;
  34.             } else {
  35.                 System.out.printf("Daily limit exceeded! You've bought %d products.%n",productsCount);
  36.             }
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement