Advertisement
Guest User

PoolPipes

a guest
Jul 16th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package pr101;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class Pipes {
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner input = new Scanner(System.in);
  10.  
  11.         int v = Integer.valueOf(input.nextLine());
  12.         int pOne = Integer.valueOf(input.nextLine());
  13.         int pTwo = Integer.valueOf(input.nextLine());
  14.         double h = Double.valueOf(input.nextLine());
  15.  
  16.         double pOneFullForH = (double)pOne * h;
  17.         double pTwoFullForH = (double)pTwo * h;
  18.  
  19.         double percentsPoolFull = ((pOneFullForH + pTwoFullForH) / v) * 100;
  20.         double percntsPipeOne = Math.floor((pOneFullForH / (pOneFullForH + pTwoFullForH)) * 100);
  21.         double percntsPipeTwo = Math.floor((pTwoFullForH / (pOneFullForH + pTwoFullForH)) * 100);
  22.  
  23.         if ((pOneFullForH + pTwoFullForH) <= v)
  24.         {
  25.             System.out.printf("The pool is %d%% full. Pipe 1: %d%%. Pipe 2: %d%%.%n", (int)percentsPoolFull, (int)percntsPipeOne, (int)percntsPipeTwo);
  26.         }
  27.         else
  28.         {
  29.             double overFlows = Math.abs(v - (pOneFullForH + pTwoFullForH));
  30.             DecimalFormat df = new DecimalFormat("0.#########");
  31.  
  32.             System.out.printf("For %s hours the pool overflows with %s liters.", df.format(h), df.format(overFlows));
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement