Sim0o0na

Untitled

Jan 18th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. /**
  5. * Created by todor on 18.01.2017 г..
  6. */
  7. public class u18v2_PipesInPool {
  8. public static void main(String[] args) {
  9.  
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. int poolVolume = Integer.parseInt(scan.nextLine());
  13. int volumePerHourPipe1 = Integer.parseInt(scan.nextLine());
  14. int volumePerHourPipe2 = Integer.parseInt(scan.nextLine());
  15. double time = Double.parseDouble(scan.nextLine());
  16. DecimalFormat decimalFormat = new DecimalFormat("#.##");
  17.  
  18. double filledVolume = ((volumePerHourPipe1 + volumePerHourPipe2)* time);
  19. double volumeDifference = filledVolume - poolVolume;
  20.  
  21. if (volumeDifference > 0) {
  22. System.out.printf("For %s hours the pool overflows with %s liters.", decimalFormat.format(time).replace(",", "."), decimalFormat.format(volumeDifference).replace(",", "."));
  23. }
  24. else {
  25. int filledPercentages = (int) ((filledVolume *100 )/ poolVolume);
  26. int filledPercentagesPipe1 = (int) ((volumePerHourPipe1 * time * 100) / filledVolume);
  27. int filledPercentagesPipe2 = (int) ((volumePerHourPipe2 * time * 100) / filledVolume);
  28. System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.", filledPercentages, filledPercentagesPipe1, filledPercentagesPipe2);
  29. }
  30. }
  31. }
Add Comment
Please, Sign In to add comment