Advertisement
veronikaaa86

[Java] Pipes In The Pool

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