Advertisement
veronikaaa86

05. Suitcases Load

Jun 19th, 2021
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package examPrep;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05SuitcasesLoad {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. double trunkCapacity = Double.parseDouble(scanner.nextLine());
  10.  
  11. String input = scanner.nextLine();
  12.  
  13. int countSuitcase = 0;
  14. boolean isFull = false;
  15. while (!input.equals("End")) {
  16. double volumeSuitcase = Double.parseDouble(input);
  17. countSuitcase++;
  18.  
  19. if (countSuitcase % 3 == 0) {
  20. volumeSuitcase = volumeSuitcase * 1.10;
  21. }
  22.  
  23. trunkCapacity = trunkCapacity - volumeSuitcase;
  24.  
  25. if (trunkCapacity <= 0) {
  26. //System.out.println("No more space!");
  27. isFull = true;
  28. countSuitcase--;
  29. break;
  30. }
  31.  
  32. input = scanner.nextLine();
  33. }
  34.  
  35. if (!isFull) {
  36. System.out.println("Congratulations! All suitcases are loaded!");
  37. } else {
  38. System.out.println("No more space!");
  39. }
  40. System.out.printf("Statistic: %d suitcases loaded.%n", countSuitcase);
  41. }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement