Advertisement
veronikaaa86

05. Suitcases Load

Jun 24th, 2023
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05SuitcasesLoad {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         double trunkCapacity = Double.parseDouble(scanner.nextLine());
  10.  
  11.         double copyTrunkCapacity = trunkCapacity;
  12.         String input = scanner.nextLine();
  13.  
  14.         boolean isFull = false;
  15.         int count = 0;
  16.         while (!input.equals("End")) {
  17.             double volumeSuitcase = Double.parseDouble(input);
  18.  
  19.             count++;
  20.  
  21.             if (count % 3 == 0) {
  22.                 volumeSuitcase = volumeSuitcase * 1.10;
  23.             }
  24.  
  25.             copyTrunkCapacity = copyTrunkCapacity - volumeSuitcase;
  26.  
  27.             if (copyTrunkCapacity < 0) {
  28.                 isFull = true;
  29.                 count--;
  30.                 break;
  31.             }
  32.  
  33.             input = scanner.nextLine();
  34.         }
  35.  
  36.         if (isFull) {
  37.             System.out.println("No more space!");
  38.         } else {
  39.             System.out.println("Congratulations! All suitcases are loaded!");
  40.         }
  41.  
  42.         System.out.printf("Statistic: %d suitcases loaded.%n", count);
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement