Advertisement
P_Donchev

SoftUni Problems - Load Suitcases (Vlastomar)

Apr 16th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SuitcaseLoad2 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double volRemain = Double.parseDouble(scan.nextLine());
  8.  
  9.         String volumeSuitcase;
  10.  
  11.         double counter = 0;
  12.         boolean checkForBreak = false;
  13.  
  14.         while (true) {
  15.             //double volSuitcase = 0.00;
  16.             // if (volumeSuitcase.isEmpty()) break;
  17.             volumeSuitcase = scan.nextLine();
  18.             if ("End".equals(volumeSuitcase)) {
  19.                 break;
  20.             }
  21.             double volSuitcase = Double.parseDouble(volumeSuitcase);
  22.            
  23.             if (counter % 2 == 0 && counter !=0) {
  24.                 volSuitcase = volSuitcase * 1.10;
  25.             }
  26.            
  27.             if (volRemain < volSuitcase) {
  28.                 checkForBreak = true;
  29.                 break;
  30.             } else if (volRemain == volSuitcase ) {
  31.                 if (volRemain != 0 && (counter + 1)% 3 != 0) {
  32.                     counter++;
  33.                 }
  34.                 checkForBreak = true;
  35.                 break;
  36.             }
  37.             volRemain = volRemain - volSuitcase;
  38.             counter++;
  39.         }
  40.        
  41.         if (checkForBreak) {
  42.             System.out.println("No more space!");
  43.         } else {
  44.             System.out.println("Congratulations! All suitcases are loaded!");
  45.         }
  46.         System.out.printf("Statistic: %.0f suitcases loaded.", counter);
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement