Advertisement
Spocoman

Trip Expenses

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