chavdardim1990

MineralWater

Oct 14th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. package com.telerikacademy.web.springdemo;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. /**
  8. * All cases
  9. * 1. Truck capacity is equal to all big bottles
  10. * 2. Truck capacity is more than all bottles
  11. * 3. Truck capacity is less than all big bottles
  12. * 3.1 Truck capacity is not equally divided to the big bottles
  13. * 3.1.1 The remainder is equal to all small bottles
  14. * 3.1.2 The remainder is more than all small bottles
  15. * 3.1.3 The remainder is less than all small bottles
  16. * 4. Truck capacity is more than all big bottles
  17. * 4.1 The small bottles are less than the left space
  18. * 4.2 The small bottles are equal or more than to the left space
  19. */
  20.  
  21. public static void main(String[] args) {
  22.  
  23. Scanner scanner = new Scanner(System.in);
  24. int allSmallBottles = Integer.parseInt(scanner.nextLine());
  25. int allBigBottles = Integer.parseInt(scanner.nextLine()) * 5;
  26. int truckCapacity = Integer.parseInt(scanner.nextLine());
  27.  
  28. int allBottles = allSmallBottles + allBigBottles;
  29. int freeCapacity = truckCapacity - allBigBottles;
  30. int truckIsFull = 0;
  31. int truckNotFull = -1;
  32.  
  33.  
  34. if (truckCapacity == allBigBottles){
  35. System.out.println(truckIsFull);
  36. } else if (truckCapacity > allBottles){
  37. System.out.println(truckNotFull);
  38. } else if (allBigBottles > truckCapacity){
  39. int remainder = truckCapacity % 5;
  40. if (remainder == 0){
  41. System.out.println(truckIsFull);
  42. } else {
  43. System.out.println(remainder);
  44. if (remainder > allSmallBottles){
  45. System.out.println(-1);
  46. } else{
  47. System.out.println(remainder);
  48. }
  49. }
  50. } else {
  51. if (freeCapacity > allSmallBottles) {
  52. System.out.println(truckNotFull);
  53. } else {
  54. System.out.println(freeCapacity);
  55. }
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment