Advertisement
Guest User

JavaSuitcases

a guest
Mar 29th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Test5SuitcasesLoad {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double capacity = Double.parseDouble(scan.nextLine());
  8.         String restriction = scan.nextLine();
  9.         int counter = 0;
  10.  
  11.         while (!restriction.equals("End")) {
  12.             double volume = Double.parseDouble(restriction);
  13.             counter++;
  14.             if (counter % 3 == 0) {
  15.                 volume = volume * 1.1;
  16.             }
  17.             if (volume > capacity) {
  18.                 System.out.println("No more space!");
  19.                 System.out.printf("Statistic: %d suitcases loaded.", counter - 1);
  20.                 return;
  21.             }
  22.             capacity = capacity - volume;
  23.             restriction = scan.nextLine();
  24.         }
  25.         System.out.println("Congratulations! All suitcases are loaded!");
  26.         System.out.printf("Statistic: %d suitcases loaded.", counter);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement