PePetrov96

Java Basics - 06. Suitcases Load

Aug 17th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | Help | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Task {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double PlaneCapacity = Double.parseDouble(scanner.nextLine());
  7.         String input = scanner.nextLine();
  8.  
  9.         int counter = 0;
  10.  
  11.         while (PlaneCapacity > 0) {
  12.             counter++;
  13.  
  14.             while (input.isEmpty()) {
  15.                 input = scanner.nextLine();
  16.             }
  17.  
  18.             if ("End".equals(input)) {
  19.                 System.out.println("Congratulations! All suitcases are loaded!");
  20.                 --counter;
  21.                 break;
  22.             }
  23.  
  24.             double load = Double.parseDouble(input);
  25.  
  26.             if (counter % 3 == 0) {
  27.                 load *= 1.10;
  28.             }
  29.             if (load <= (PlaneCapacity)) {
  30.                 PlaneCapacity -= load;
  31.             } else {
  32.                 System.out.println("No more space!");
  33.                 --counter;
  34.                 break;
  35.             }
  36.             input = scanner.nextLine();
  37.         }
  38.         System.out.printf("Statistic: %d suitcases loaded.", counter);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment