Advertisement
CR7CR7

suitcaseAirplane

Apr 19th, 2023
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SuitcaseLoader {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         // Read the capacity of the airplane trunk
  8.         double capacity = Double.parseDouble(scanner.nextLine());
  9.         // Initialize a variable to store the number of loaded suitcases
  10.         int count = 0;
  11.         // Initialize a variable to store the command or the volume of a suitcase
  12.         String input = scanner.nextLine();
  13.         // Loop until the command "End" is received or the capacity is exceeded
  14.         while (!input.equals("End")) {
  15.            double volume = Double.parseDouble(input);
  16.             // Increase the volume by 10% for every third suitcase
  17.             if (count % 3 == 0) {
  18.                 volume *= 1.1;
  19.             }
  20.             // Check if there is enough space for the suitcase
  21.             if (capacity >= volume) {
  22.                 // Subtract the volume from the capacity
  23.                 capacity -= volume;
  24.                 // Increment the count of loaded suitcases
  25.                 count++;
  26.             } else {
  27.                 // Break the loop if there is no more space
  28.                 break;
  29.             }
  30.             // Read the next input
  31.             input = scanner.nextLine();
  32.         }
  33.         // Close the scanner
  34.         scanner.close();
  35.         // Print the appropriate message depending on the input and capacity
  36.         if (input.equals("End")) {
  37.             System.out.println("Congratulations! All suitcases are loaded!");
  38.         } else {
  39.             System.out.println("No more space!");
  40.         }
  41.         // Print the statistic of how many suitcases are loaded
  42.         System.out.println("Statistic: " + count + " suitcases loaded!");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement