Advertisement
YavorGrancharov

PipesInPool

Jan 15th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class PipesInPool {
  5.     public static void main(String[] args) {
  6.         Scanner console = new Scanner(System.in);
  7.         DecimalFormat format = new DecimalFormat("0.##");
  8.         int V = Integer.parseInt(console.nextLine());
  9.         int P1 = Integer.parseInt(console.nextLine());
  10.         int P2 = Integer.parseInt(console.nextLine());
  11.         double H = Double.parseDouble(console.nextLine());
  12.         double water = P1 * H + P2 * H;
  13.  
  14.         if (water <= V) {
  15.             double full = (water / V) * 100;
  16.             double fullP1 = (P1 * H / water) * 100;
  17.             double fullP2 = (P2 * H / water) * 100;
  18.  
  19.             System.out.println("The pool is " + (int)full + "% " + "full. Pipe 1: " + (int)fullP1 + "%" + ". " + "Pipe 2: " + (int)fullP2 + "%" + ".");
  20.         } else {
  21.             double over = water - V;
  22.  
  23.             System.out.println("For " + format.format(H) + " hours the pool overflows with " + format.format(over) + " liters.");
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement