Advertisement
Valantina

TripExpenses/Ex/27.07.2019/JAVA

Jul 29th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P06_TripExpenses {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int daysOfTrip = Integer.parseInt(scan.nextLine());
  8.         double moneyLeft = 0.0;
  9.         for (int i = 0; i < daysOfTrip; i++) {
  10.             double dayLimit = 60 + moneyLeft;
  11.             moneyLeft = 0;
  12.             String input = scan.nextLine();
  13.             int products = 0;
  14.             while (!"Day over".equals(input)) {
  15.                 double price = Double.parseDouble(input);
  16.                 if (dayLimit - price >= 0) {
  17.                     dayLimit -= price;
  18.                     products++;
  19.                 } else {
  20.                     input = scan.nextLine();
  21.                     continue;
  22.                 }
  23.                 if (dayLimit == 0) {
  24.                     break;
  25.                 }
  26.                 input = scan.nextLine();
  27.             }
  28.             if ("Day over".equals(input)) {
  29.                 moneyLeft = Math.abs(moneyLeft - dayLimit);
  30.                 System.out.println(String.format("Money left from today: %.2f. You've bought %d products.", moneyLeft, products));
  31.             } else {
  32.                 System.out.println(String.format("Daily limit exceeded! You've bought %d products.", products));
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement