marmotka

Pool pipes

Mar 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class p18_Pipes_in_pool {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int v = Integer.parseInt(scanner.nextLine());
  10.         int p1 = Integer.parseInt(scanner.nextLine());
  11.         int p2 = Integer.parseInt(scanner.nextLine());
  12.         double h = Double.parseDouble(scanner.nextLine());
  13.  
  14.         double fullness = p1 * h + p2 * h;
  15.  
  16.         double x = fullness * 100 / v;
  17.         double y = p1 * h / fullness * 100;
  18.         double z = p2 * h / fullness * 100;
  19.  
  20.         if (fullness > v) {
  21.             DecimalFormat df = new DecimalFormat("0.##");
  22.             System.out.printf("For %s hours the pool overflows with %d liters.", df.format(h), (int) (fullness - v));
  23.         } else {
  24.             System.out.printf("The pool is %s%% full. Pipe 1: %s%%. Pipe 2: %s%%.", (int) x, (int) y, (int) z);
  25.  
  26.         }
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment