Advertisement
veronikaaa86

05. Suitcases Load

Apr 9th, 2022
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. package examPreparation;
  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. boolean isFull = false;
  12. double copyTrunkCapacity = trunkCapacity;
  13. int countSuitcase = 0;
  14. String input = scanner.nextLine();
  15. while (!input.equals("End")) {
  16. double volumeSuitcase = Double.parseDouble(input);
  17. countSuitcase++;
  18. if (countSuitcase % 3 == 0) {
  19. volumeSuitcase = volumeSuitcase * 1.10;
  20. }
  21.  
  22. copyTrunkCapacity = copyTrunkCapacity - volumeSuitcase;
  23. if (copyTrunkCapacity <= 0) {
  24. isFull = true;
  25. countSuitcase--;
  26. break;
  27. }
  28.  
  29. input = scanner.nextLine();
  30. }
  31.  
  32. if (isFull) {
  33. System.out.println("No more space!");
  34. } else {
  35. System.out.println("Congratulations! All suitcases are loaded!");
  36. }
  37. System.out.printf("Statistic: %d suitcases loaded.%n", countSuitcase);
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement