grach

Suitcases Load - 28-29 March 2020 edited

Apr 23rd, 2020
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Suitcases_load {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double capacity = Double.parseDouble(scanner.nextLine());
  8.  
  9.         String command = scanner.nextLine();
  10.         int counter = 0;
  11.  
  12.         while (!"End".equals(command)) {
  13.  
  14.             double suitcaseVolume = Double.parseDouble(command);
  15.  
  16.             counter++;
  17.  
  18.             if (counter % 3 == 0) {
  19.                 suitcaseVolume *= 1.1;
  20.             }
  21.             capacity -= suitcaseVolume;
  22.  
  23.             if (capacity < 0) {
  24.                 counter--;
  25.                 break;
  26.             }
  27.  
  28.             command = scanner.nextLine();
  29.         }
  30.         if (command.equals("End")) {
  31.             System.out.println("Congratulations! All suitcases are loaded!");
  32.         } else {
  33.             System.out.println("No more space!");
  34.         }
  35.         // System.out.println("Останало к-во " + capacity);
  36.         System.out.println("Statistic: " + counter + " suitcases loaded.");
  37.  
  38.     }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /*import java.util.Scanner;
  50.  
  51. public class SuitcasesLoad {
  52.     public static void main(String[] args) {
  53.         Scanner scan = new Scanner(System.in);
  54.  
  55.         double capacity = Double.parseDouble(scan.nextLine());
  56.  
  57.         String command = scan.nextLine();
  58.         int counter = 0;
  59.  
  60.         while (!"End".equals(command)) {
  61.  
  62.             double suitcaseVolume = Double.parseDouble(command);
  63.  
  64.             if (counter % 3 == 0) {
  65.                 suitcaseVolume *= 1.1;
  66.             }
  67.             capacity -= suitcaseVolume;
  68.  
  69.             if (capacity < 0) {
  70.                 break;
  71.             }
  72.             counter++;
  73.             //System.out.println(capacity);
  74.  
  75.             command = scan.nextLine();
  76.         }
  77.         if (capacity >= 0) {
  78.             System.out.println("Congratulations! All suitcases are loaded!");
  79.         } else {
  80.             System.out.println("No more space!");
  81.         }
  82.         // System.out.println("Останало к-во " + capacity);
  83.         System.out.println("Statistic: " + counter + " suitcases loaded.");
  84.     }
  85. }*/
Advertisement
Add Comment
Please, Sign In to add comment