Advertisement
zigrek

Untitled

Jan 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PipesInPool {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int V = Integer.parseInt(scanner.nextLine());
  8. int P1 = Integer.parseInt(scanner.nextLine());
  9. int P2 = Integer.parseInt(scanner.nextLine());
  10. double H = Double.parseDouble(scanner.nextLine());
  11. double filled = P1*H + P2*H;
  12.  
  13. if (V >= 10000){
  14. System.out.println("Invalid input!");
  15. } else if (P1 >= 5000) {
  16. System.out.println("Invalid input!");
  17. }else if (P2 >= 5000) {
  18. System.out.println("Invalid input!");
  19. }else if (H >= 24) {
  20. System.out.println("Invalid input!");
  21. }
  22.  
  23. else if (filled > V) {
  24. double overflow = filled - V;
  25. System.out.printf("For %s hours the pool overflows with %.1f liters.", H, overflow);
  26. } else {
  27. double percentall = Math.floor((filled/V)*100);
  28. double percentP1 = Math.floor(((P1*H)/filled)*100);
  29. double percentP2 = Math.floor(((P2*H)/filled)*100);
  30. System.out.printf("The pool is %.0f%% full. Pipe 1: %.0f%%. Pipe 2: %.0f%%.", percentall, percentP1, percentP2);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement